Crow  1.1
A C++ microframework for the web
crow::detail::task_timer Class Reference

#include <task_timer.h>

Public Types

using task_type = std::function< void()>
 
using identifier_type = size_t
 

Public Member Functions

 task_timer (asio::io_service &io_service, const std::chrono::milliseconds tick_length=std::chrono::seconds(1))
 
void cancel (identifier_type id)
 
identifier_type schedule (const task_type &task)
 
identifier_type schedule (const task_type &task, uint8_t timeout)
 Schedule the given task to be executed after the given time. More...
 
void set_default_timeout (uint8_t timeout)
 
uint8_t get_default_timeout () const
 Get the default timeout. (Default: 5)
 
std::chrono::milliseconds get_tick_length () const
 returns the length of one tick.
 

Detailed Description

A class for scheduling functions to be called after a specific amount of ticks. Ther tick length can be handed over in constructor, the default tick length is equal to 1 second.

Member Function Documentation

◆ cancel()

void crow::detail::task_timer::cancel ( identifier_type  id)
inline

Cancel the scheduling of the given task

Parameters
identifier_typetask identifier of the task to cancel.

◆ schedule() [1/2]

identifier_type crow::detail::task_timer::schedule ( const task_type &  task)
inline

Schedule the given task to be executed after the default amount of ticks.

Returns
identifier_type Used to cancel the thread. It is not bound to this task_timer instance and in some cases could lead to undefined behavior if used with other task_timer objects or after the task has been successfully executed.

◆ schedule() [2/2]

identifier_type crow::detail::task_timer::schedule ( const task_type &  task,
uint8_t  timeout 
)
inline

Schedule the given task to be executed after the given time.

Parameters
timeoutThe amount of ticks to wait before execution.
Returns
identifier_type Used to cancel the thread. It is not bound to this task_timer instance and in some cases could lead to undefined behavior if used with other task_timer objects or after the task has been successfully executed.

◆ set_default_timeout()

void crow::detail::task_timer::set_default_timeout ( uint8_t  timeout)
inline

Set the default timeout for this task_timer instance. (Default: 5)

Parameters
timeoutThe amount of ticks to wait before execution. For tick length
See also
tick_length_ms_

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