Timers & EventsΒΆ
Timers or, more generically, Events are useful abstractions for deferring execution of certain logic and to avoid blocking the reactor. For example, assume that you want to emit metrics every 30 seconds. The basis for scheduling your metrics emission within Pembroke might look like:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | #include <chrono>
#include <pembroke/pembroke.hpp>
using namespace pembroke;
using namespace std::chrono_literals;
class MetricsEmitter {
event::TimerEvent m_te;
public:
MetricsEmitter(const reactor &r) {
m_te = event::TimerEvent(30s, [this]() -> {
this->emit_metrics();
});
assert(r.register_event(m_te));
}
void emit_metrics();
}
|
See the API Docs for more details on the types of events that can be used within Pembroke.