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

Owns one scheduled timer and cancels it when destroyed. Move-only. More...

#include <scheduler.hpp>

Public Member Functions

 TimerHandle ()=default
 A handle that owns no timer.
 TimerHandle (std::function< void()> cancel, std::function< bool()> isScheduled={})
 Takes ownership of a timer through the function that cancels it.
 ~TimerHandle ()
 Cancels the timer, if this handle still owns one.
 TimerHandle (TimerHandle const &)=delete
TimerHandle & operator= (TimerHandle const &)=delete
 TimerHandle (TimerHandle &&other) noexcept
 Takes over other's timer; other then owns none.
TimerHandle & operator= (TimerHandle &&other) noexcept
 Cancels this handle's timer, then takes over other's.
void cancel () noexcept
 Cancels the timer, if this handle still owns one.
bool active () const noexcept
 Whether this handle still owns a scheduled timer.

Detailed Description

Owns one scheduled timer and cancels it when destroyed. Move-only.

A scheduler hands it two functions: one that cancels the timer and one that says whether the timer is still scheduled. So active() turns false once a one-shot timer has fired, and cancelling a fired timer does nothing.

Definition at line 19 of file scheduler.hpp.

Constructor & Destructor Documentation

◆ TimerHandle() [1/2]

morph::reactive::TimerHandle::TimerHandle ( std::function< void()> cancel,
std::function< bool()> isScheduled = {} )
inlineexplicit

Takes ownership of a timer through the function that cancels it.

Parameters
cancelCancels the timer; called at most once. It must tolerate a timer that has already fired or whose scheduler is gone.
isScheduledWhether the timer is still scheduled: false once a one-shot timer has fired or its scheduler is gone. Empty means the handle cannot tell, and active() stays true until cancel().

Definition at line 29 of file scheduler.hpp.

◆ ~TimerHandle()

morph::reactive::TimerHandle::~TimerHandle ( )
inline

Cancels the timer, if this handle still owns one.

Definition at line 33 of file scheduler.hpp.

◆ TimerHandle() [2/2]

morph::reactive::TimerHandle::TimerHandle ( TimerHandle && other)
inlinenoexcept

Takes over other's timer; other then owns none.

Parameters
otherThe handle to move from.

Definition at line 40 of file scheduler.hpp.

Member Function Documentation

◆ operator=()

TimerHandle & morph::reactive::TimerHandle::operator= ( TimerHandle && other)
inlinenoexcept

Cancels this handle's timer, then takes over other's.

Parameters
otherThe handle to move from.
Returns
*this.

Definition at line 46 of file scheduler.hpp.

◆ cancel()

void morph::reactive::TimerHandle::cancel ( )
inlinenoexcept

Cancels the timer, if this handle still owns one.

Definition at line 56 of file scheduler.hpp.

◆ active()

bool morph::reactive::TimerHandle::active ( ) const
inlinenodiscardnoexcept

Whether this handle still owns a scheduled timer.

Returns
False after cancel(), after a move from it, for a default-constructed handle, and once a one-shot timer has fired or its scheduler is gone (when the scheduler can say so).

Definition at line 71 of file scheduler.hpp.


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