esphome-api-client 0.5.0
Modern C++17 client for the ESPHome native API (plaintext + Noise)
Loading...
Searching...
No Matches
executor.hpp
Go to the documentation of this file.
1#pragma once
2
6
7#include <chrono>
8#include <cstdint>
9#include <functional>
10
11namespace esphome::api {
12
14using TimerId = std::uint64_t;
15inline constexpr TimerId invalid_timer = 0;
16
20class Executor {
21public:
22 virtual ~Executor() = default;
23
25 virtual void post(std::function<void()> fn) = 0;
26
28 virtual TimerId schedule_after(std::chrono::milliseconds delay, std::function<void()> fn) = 0;
29
31 virtual void cancel(TimerId id) = 0;
32};
33
34} // namespace esphome::api
Minimal executor: deferred execution plus one-shot timers.
Definition executor.hpp:20
virtual TimerId schedule_after(std::chrono::milliseconds delay, std::function< void()> fn)=0
Run fn once after delay. Returns a handle usable with cancel.
virtual ~Executor()=default
virtual void post(std::function< void()> fn)=0
Run fn soon, on the executor (never inline / re-entrantly).
virtual void cancel(TimerId id)=0
Cancel a pending timer (no-op if it already fired or was cancelled).
Definition bytes.hpp:10
std::uint64_t TimerId
Opaque handle to a scheduled timer; invalid_timer means "no timer".
Definition executor.hpp:14
constexpr TimerId invalid_timer
Definition executor.hpp:15