morph 0.1.0
Asynchronous bridge between GUI thread and business models
Loading...
Searching...
No Matches
morph::reactive::Scheduler Class Referenceabstract

Runs callbacks after a delay or on a period, on the runtime's owner executor. More...

#include <scheduler.hpp>

Inheritance diagram for morph::reactive::Scheduler:
morph::qt_quick::QtScheduler morph::reactive::testing::ManualScheduler

Public Member Functions

 Scheduler (Scheduler const &)=delete
Scheduler & operator= (Scheduler const &)=delete
 Scheduler (Scheduler &&)=delete
Scheduler & operator= (Scheduler &&)=delete
virtual TimerHandle after (std::chrono::milliseconds delay, std::function< void()> fn)=0
 Runs fn once, delay from now.
virtual TimerHandle every (std::chrono::milliseconds period, std::function< void()> fn)=0
 Runs fn every period, starting one period from now.

Detailed Description

Runs callbacks after a delay or on a period, on the runtime's owner executor.

Every frontend provides one, on its own event loop's timers; a test uses testing::ManualScheduler. Every implementation guarantees:

  • Callbacks run on the owner executor of the Runtime the timers serve.
  • A one-shot timer's handle reports active() false once the timer has fired.
  • Once a handle's cancel() returns on the owner, its callback never runs, even when its deadline has passed and a call is already queued.
  • cancel() may be called from inside a callback, its own timer's included.
  • A TimerHandle may outlive its Scheduler; cancelling it then does nothing.
  • every() fires once per period while the owner runs. If the owner is blocked past several periods, a frontend fires once and counts the next deadline from that firing: no burst of missed firings.

Definition at line 105 of file scheduler.hpp.

Member Function Documentation

◆ after()

virtual TimerHandle morph::reactive::Scheduler::after ( std::chrono::milliseconds delay,
std::function< void()> fn )
nodiscardpure virtual

Runs fn once, delay from now.

Parameters
delayHow long to wait; a non-positive delay means as soon as possible.
fnThe callback.
Returns
The handle; destroying it before the deadline cancels the call.

Implemented in morph::qt_quick::QtScheduler, and morph::reactive::testing::ManualScheduler.

◆ every()

virtual TimerHandle morph::reactive::Scheduler::every ( std::chrono::milliseconds period,
std::function< void()> fn )
nodiscardpure virtual

Runs fn every period, starting one period from now.

Parameters
periodThe interval; must be positive.
fnThe callback.
Returns
The handle; destroying it stops the repetition.
Exceptions
std::invalid_argumentwhen period is not positive.

Implemented in morph::qt_quick::QtScheduler, and morph::reactive::testing::ManualScheduler.


The documentation for this class was generated from the following file: