Async++ unknown
Async (co_await/co_return) code for C++
Loading...
Searching...
No Matches
asyncpp::timer Class Referencefinal

A dispatcher that provides a way to schedule coroutines based on time. More...

#include <asyncpp/timer.h>

Inheritance diagram for asyncpp::timer:
[legend]

Public Member Functions

 timer ()
 Construct a new timer.
 
 timer (const timer &)=delete
 
timeroperator= (const timer &)=delete
 
void push (std::function< void()> cbfn) override
 Push a callback to be executed in the timer thread.
 
void schedule (std::function< void(bool)> cbfn, std::chrono::steady_clock::time_point timeout)
 Schedule a callback to be executed at a specific point in time.
 
void schedule (std::function< void(bool)> cbfn, std::chrono::nanoseconds timeout)
 Schedule a callback to be executed after a certain duration expires.
 
template<typename Clock , typename Duration >
void schedule (std::function< void(bool)> cbfn, std::chrono::time_point< Clock, Duration > timeout)
 Schedule a callback to be executed after a certain duration expires.
 
void schedule (std::function< void(bool)> cbfn, std::chrono::steady_clock::time_point timeout, asyncpp::stop_token stoken)
 Schedule a callback to be executed at a specific point in time with a stop_token.
 
void schedule (std::function< void(bool)> cbfn, std::chrono::nanoseconds timeout, asyncpp::stop_token stoken)
 Schedule a callback to be executed after a certain duration expires with a stop_token.
 
template<typename Clock , typename Duration >
void schedule (std::function< void(bool)> cbfn, std::chrono::time_point< Clock, Duration > timeout, asyncpp::stop_token stoken)
 Schedule a callback to be executed after a certain duration expires with a stop_token.
 
auto wait (std::chrono::steady_clock::time_point timeout) noexcept
 Get an awaitable that pauses the current coroutine until the specified time_point is reached.
 
template<typename Rep , typename Period >
auto wait (std::chrono::duration< Rep, Period > timeout) noexcept
 Get an awaitable that pauses the current coroutine until the specified duration is elapsed.
 
template<typename Clock , typename Duration >
auto wait (std::chrono::time_point< Clock, Duration > timeout)
 Get an awaitable that pauses the current coroutine until the specified duration is elapsed.
 
auto wait (std::chrono::steady_clock::time_point timeout, asyncpp::stop_token stoken) noexcept
 Get an awaitable that pauses the current coroutine until the specified time_point is reached, allows cancellation.
 
template<typename Rep , typename Period >
auto wait (std::chrono::duration< Rep, Period > timeout, asyncpp::stop_token stoken) noexcept
 Get an awaitable that pauses the current coroutine until the specified duration is elapsed, allows cancellation.
 
template<typename Clock , typename Duration >
auto wait (std::chrono::time_point< Clock, Duration > timeout, asyncpp::stop_token stoken)
 Get an awaitable that pauses the current coroutine until the specified duration is elapsed, allows cancellation.
 

Static Public Member Functions

static timerget_default ()
 Get a global timer instance.
 
- Static Public Member Functions inherited from asyncpp::dispatcher
static dispatchercurrent () noexcept
 

Additional Inherited Members

- Static Protected Member Functions inherited from asyncpp::dispatcher
static dispatchercurrent (dispatcher *disp)
 Set the current dispatcher for this thread and reurns the current one. Implementers of dispatchers can use this to give convenient access to the current dispatcher, for example for yielding. A dispatcher usually calls this function once at the start of an event loop, before calling any callbacks and persists the return value. It then calls it again after calling all callbacks and restores the previously persisted value. This allows invoking a dispatcher loop from within another dispatcher. The end call is optional if the implementation can guarantee that the thread will terminate afterwards.
 

Detailed Description

A dispatcher that provides a way to schedule coroutines based on time.

Member Function Documentation

◆ push()

void asyncpp::timer::push ( std::function< void()> cbfn)
inlineoverridevirtual

Push a callback to be executed in the timer thread.

Parameters
cbfnCallback to execute

Implements asyncpp::dispatcher.

◆ schedule() [1/6]

void asyncpp::timer::schedule ( std::function< void(bool)> cbfn,
std::chrono::nanoseconds timeout )
inline

Schedule a callback to be executed after a certain duration expires.

Parameters
cbfnThe callbackto execute
timeoutThe duration to wait before executing the callback

◆ schedule() [2/6]

void asyncpp::timer::schedule ( std::function< void(bool)> cbfn,
std::chrono::nanoseconds timeout,
asyncpp::stop_token stoken )
inline

Schedule a callback to be executed after a certain duration expires with a stop_token.

Parameters
cbfnThe callbackto execute
timeoutThe duration to wait before executing the callback
stokenstop_token allowing to cancel the callback

◆ schedule() [3/6]

void asyncpp::timer::schedule ( std::function< void(bool)> cbfn,
std::chrono::steady_clock::time_point timeout )
inline

Schedule a callback to be executed at a specific point in time.

Parameters
cbfnThe callback to execute
timeoutThe time_point at which the callback should get executed

◆ schedule() [4/6]

void asyncpp::timer::schedule ( std::function< void(bool)> cbfn,
std::chrono::steady_clock::time_point timeout,
asyncpp::stop_token stoken )
inline

Schedule a callback to be executed at a specific point in time with a stop_token.

Parameters
cbfnThe callback to execute
timeoutThe time_point at which the callback should get executed
stokenstop_token allowing to cancel the callback

◆ schedule() [5/6]

template<typename Clock , typename Duration >
void asyncpp::timer::schedule ( std::function< void(bool)> cbfn,
std::chrono::time_point< Clock, Duration > timeout )
inline

Schedule a callback to be executed after a certain duration expires.

Parameters
cbfnThe callbackto execute
timeoutThe duration to wait before executing the callback

◆ schedule() [6/6]

template<typename Clock , typename Duration >
void asyncpp::timer::schedule ( std::function< void(bool)> cbfn,
std::chrono::time_point< Clock, Duration > timeout,
asyncpp::stop_token stoken )
inline

Schedule a callback to be executed after a certain duration expires with a stop_token.

Parameters
cbfnThe callbackto execute
timeoutThe duration to wait before executing the callback
stokenstop_token allowing to cancel the callback

◆ wait() [1/6]

template<typename Rep , typename Period >
auto asyncpp::timer::wait ( std::chrono::duration< Rep, Period > timeout)
inlinenoexcept

Get an awaitable that pauses the current coroutine until the specified duration is elapsed.

Returns
An awaitable

◆ wait() [2/6]

template<typename Rep , typename Period >
auto asyncpp::timer::wait ( std::chrono::duration< Rep, Period > timeout,
asyncpp::stop_token stoken )
inlinenoexcept

Get an awaitable that pauses the current coroutine until the specified duration is elapsed, allows cancellation.

Parameters
timeoutThe duration to wait for
stokenA stop_token that allows cancellation of the wait
Returns
An awaitable

◆ wait() [3/6]

auto asyncpp::timer::wait ( std::chrono::steady_clock::time_point timeout)
inlinenoexcept

Get an awaitable that pauses the current coroutine until the specified time_point is reached.

Returns
An awaitable

◆ wait() [4/6]

auto asyncpp::timer::wait ( std::chrono::steady_clock::time_point timeout,
asyncpp::stop_token stoken )
inlinenoexcept

Get an awaitable that pauses the current coroutine until the specified time_point is reached, allows cancellation.

Parameters
timeoutThe time_point to wait for
stokenA stop_token that allows cancellation of the wait
Returns
An awaitable

◆ wait() [5/6]

template<typename Clock , typename Duration >
auto asyncpp::timer::wait ( std::chrono::time_point< Clock, Duration > timeout)
inline

Get an awaitable that pauses the current coroutine until the specified duration is elapsed.

Returns
An awaitable

◆ wait() [6/6]

template<typename Clock , typename Duration >
auto asyncpp::timer::wait ( std::chrono::time_point< Clock, Duration > timeout,
asyncpp::stop_token stoken )
inline

Get an awaitable that pauses the current coroutine until the specified duration is elapsed, allows cancellation.

Parameters
timeoutThe duration to wait for
stokenA stop_token that allows cancellation of the wait
Returns
An awaitable

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