|
morph 0.1.0
Asynchronous bridge between GUI thread and business models
|
A deterministic Scheduler: its clock moves only in advance(), which fires what falls due on the calling thread. More...
#include <manual_scheduler.hpp>
Public Member Functions | |
| ManualScheduler (ManualScheduler const &)=delete | |
| ManualScheduler & | operator= (ManualScheduler const &)=delete |
| ManualScheduler (ManualScheduler &&)=delete | |
| ManualScheduler & | operator= (ManualScheduler &&)=delete |
| TimerHandle | after (std::chrono::milliseconds delay, std::function< void()> fn) override |
Runs fn once, delay after the current time. | |
| TimerHandle | every (std::chrono::milliseconds period, std::function< void()> fn) override |
Runs fn every period, starting one period after the current time. | |
| void | advance (std::chrono::milliseconds delta) |
Moves the clock forward by delta, stopping at each deadline on the way to fire what is due there. | |
| std::chrono::milliseconds | now () const |
| The scheduler's clock: the sum of every advance() so far, or, inside a callback, that callback's deadline. It never decreases. | |
| std::size_t | pendingTimers () const |
| How many timers are scheduled: periodic ones until cancelled, one-shots until they fire or are cancelled. | |
| Public Member Functions inherited from morph::reactive::Scheduler | |
| Scheduler (Scheduler const &)=delete | |
| Scheduler & | operator= (Scheduler const &)=delete |
| Scheduler (Scheduler &&)=delete | |
| Scheduler & | operator= (Scheduler &&)=delete |
A deterministic Scheduler: its clock moves only in advance(), which fires what falls due on the calling thread.
advance(delta) models time passing while the owner loop runs and is never blocked: the clock stops at each deadline in turn, so every() fires once per elapsed period, and a timer a callback creates fires in the same advance when its deadline falls within it. Timers due at the same instant fire in the order they were created (a periodic timer keeps the place its first scheduling gave it). One exception keeps a self-re-arming zero-delay timer from looping: a timer a callback creates with a non-positive delay is due at the next advance(), not at the current instant.
It keeps the Scheduler contract: a timer cancelled by an earlier callback does not fire, a callback may cancel any timer, its own included, and handles may outlive the scheduler. Not thread-safe.
Definition at line 33 of file manual_scheduler.hpp.
|
inlinenodiscardoverridevirtual |
Runs fn once, delay after the current time.
| delay | How long to wait; a negative delay counts as zero, which is due at the next advance(), advance(0ms) included. |
| fn | The callback. |
Implements morph::reactive::Scheduler.
Definition at line 47 of file manual_scheduler.hpp.
|
inlinenodiscardoverridevirtual |
Runs fn every period, starting one period after the current time.
| period | The interval; must be positive. |
| fn | The callback. |
| std::invalid_argument | when period is not positive. |
Implements morph::reactive::Scheduler.
Definition at line 56 of file manual_scheduler.hpp.
|
inline |
Moves the clock forward by delta, stopping at each deadline on the way to fire what is due there.
A callback sees the clock at its own deadline. A periodic timer is next due one period after the deadline it fired for. A callback that throws ends the advance: the exception propagates, the clock stays at that deadline, the throwing timer is rescheduled (periodic) or gone (one-shot) as if it had returned, and the rest fire at the next advance.
| delta | How far to move; must not be negative. |
| std::invalid_argument | when delta is negative. |
| std::logic_error | when called from a timer callback. |
Definition at line 73 of file manual_scheduler.hpp.
|
inlinenodiscard |
The scheduler's clock: the sum of every advance() so far, or, inside a callback, that callback's deadline. It never decreases.
Definition at line 101 of file manual_scheduler.hpp.
|
inlinenodiscard |
How many timers are scheduled: periodic ones until cancelled, one-shots until they fire or are cancelled.
Definition at line 106 of file manual_scheduler.hpp.