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

A class for scheduling functions to be called after a specific amount of ticks. A tick is equal to 1 second. More...

Collaboration diagram for crow::detail::task_timer:

Public Types

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

Public Member Functions

 task_timer (boost::asio::io_service &io_service)
 
 ~task_timer ()
 
void cancel (identifier_type id)
 
identifier_type schedule (const task_type &task)
 Schedule the given task to be executed after the default amount of ticks. More...
 
identifier_type schedule (const task_type &task, std::uint8_t timeout)
 Schedule the given task to be executed after the given time. More...
 
void set_default_timeout (std::uint8_t timeout)
 Set the default timeout for this task_timer instance. (Default: 5) More...
 
std::uint8_t get_default_timeout () const
 Get the default timeout. (Default: 5) More...
 

Private Types

using clock_type = std::chrono::steady_clock
 
using time_type = clock_type::time_point
 

Private Member Functions

void process_tasks ()
 
void tick_handler (const boost::system::error_code &ec)
 

Private Attributes

std::uint8_t default_timeout_ {5}
 
boost::asio::io_service & io_service_
 
boost::asio::deadline_timer deadline_timer_
 
std::map< identifier_type, std::pair< time_type, task_type > > tasks_
 
identifier_type highest_id_ {0}
 

Detailed Description

A class for scheduling functions to be called after a specific amount of ticks. A tick is equal to 1 second.

Member Typedef Documentation

◆ task_type

using crow::detail::task_timer::task_type = std::function<void()>

◆ identifier_type

◆ clock_type

using crow::detail::task_timer::clock_type = std::chrono::steady_clock
private

◆ time_type

using crow::detail::task_timer::time_type = clock_type::time_point
private

Constructor & Destructor Documentation

◆ task_timer()

crow::detail::task_timer::task_timer ( boost::asio::io_service &  io_service)
inline
Here is the call graph for this function:

◆ ~task_timer()

crow::detail::task_timer::~task_timer ( )
inline

Member Function Documentation

◆ cancel()

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

◆ 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.
Here is the call graph for this function:

◆ schedule() [2/2]

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

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

Parameters
task.
timeoutThe amount of ticks (seconds) 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 ( std::uint8_t  timeout)
inline

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

Parameters
timeoutThe amount of ticks (seconds) to wait before execution.
Here is the caller graph for this function:

◆ get_default_timeout()

std::uint8_t crow::detail::task_timer::get_default_timeout ( ) const
inline

Get the default timeout. (Default: 5)

Here is the caller graph for this function:

◆ process_tasks()

void crow::detail::task_timer::process_tasks ( )
inlineprivate
Here is the caller graph for this function:

◆ tick_handler()

void crow::detail::task_timer::tick_handler ( const boost::system::error_code &  ec)
inlineprivate
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ default_timeout_

std::uint8_t crow::detail::task_timer::default_timeout_ {5}
private

◆ io_service_

boost::asio::io_service& crow::detail::task_timer::io_service_
private

◆ deadline_timer_

boost::asio::deadline_timer crow::detail::task_timer::deadline_timer_
private

◆ tasks_

std::map<identifier_type, std::pair<time_type, task_type> > crow::detail::task_timer::tasks_
private

◆ highest_id_

identifier_type crow::detail::task_timer::highest_id_ {0}
private

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