WPILibC++ 2024.1.1-beta-4
EventLoop.h
Go to the documentation of this file.
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5#pragma once
6
7#include <functional>
8#include <vector>
9
10#include <wpi/FunctionExtras.h>
11
12namespace frc {
13/** A declarative way to bind a set of actions to a loop and execute them when
14 * the loop is polled. */
15class EventLoop {
16 public:
18
19 EventLoop(const EventLoop&) = delete;
20 EventLoop& operator=(const EventLoop&) = delete;
21
22 /**
23 * Bind a new action to run when the loop is polled.
24 *
25 * @param action the action to run.
26 */
27 void Bind(wpi::unique_function<void()> action);
28
29 /**
30 * Poll all bindings.
31 */
32 void Poll();
33
34 /**
35 * Clear all bindings.
36 */
37 void Clear();
38
39 private:
40 std::vector<wpi::unique_function<void()>> m_bindings;
41};
42} // namespace frc
This file provides a collection of function (or more generally, callable) type erasure utilities supp...
A declarative way to bind a set of actions to a loop and execute them when the loop is polled.
Definition: EventLoop.h:15
void Clear()
Clear all bindings.
void Bind(wpi::unique_function< void()> action)
Bind a new action to run when the loop is polled.
EventLoop & operator=(const EventLoop &)=delete
void Poll()
Poll all bindings.
EventLoop(const EventLoop &)=delete
unique_function is a type-erasing functor similar to std::function.
Definition: FunctionExtras.h:57
Definition: AprilTagPoseEstimator.h:15