WPILibC++ 2027.0.0-alpha-4
Loading...
Searching...
No Matches
EventLoop.hpp
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
11
12namespace wpi {
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::util::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::util::unique_function<void()>> m_bindings;
41 bool m_running{false};
42};
43} // namespace wpi
This file provides a collection of function (or more generally, callable) type erasure utilities supp...
EventLoop & operator=(const EventLoop &)=delete
void Bind(wpi::util::unique_function< void()> action)
Bind a new action to run when the loop is polled.
EventLoop(const EventLoop &)=delete
void Clear()
Clear all bindings.
void Poll()
Poll all bindings.
unique_function is a type-erasing functor similar to std::function.
Definition FunctionExtras.hpp:57
Definition CvSource.hpp:15