asynchrony 0.0.0
Add asynchrony to your C++ applications using standard C++20
Loading...
Searching...
No Matches
siddiqsoft::periodic_worker< Pri > Struct Template Reference

Implements a simple queue + semaphore driven asynchronous processor. More...

#include </opt/azure-agent/_work/14/s/include/siddiqsoft/periodic_worker.hpp>

Public Member Functions

 periodic_worker (periodic_worker &)=delete
auto & operator= (periodic_worker &)=delete
 periodic_worker (periodic_worker &&)=delete
auto & operator= (periodic_worker &&)=delete
 ~periodic_worker ()
 Destructor Cancel the semaphore by first resetting the interval to zero. Signal the semaphore follow that by requesting thread to stop. This is slightly better than allowing the default destructors to kick in If we do not reduce the interval time and signal a release then the timeout might be quite large! If the callback hangs and does not properly check for the stop_token then we end up with a locked periodic_worker without a neat way to terminate.
void forceCleanupTerminate (const std::source_location &sl=std::source_location::current())
 This method is to be used by the user when they shutdown their application. This is best used for cases when the callback cannot be guaranteed to be "clean" or respect the stop_token.
 periodic_worker (std::function< void()> c, std::chrono::microseconds interval, std::string name={"anonymous-periodic-worker"})
 Constructor requires the callback for the thread.

Static Public Attributes

static constexpr std::chrono::milliseconds DEFAULT_WAIT_FOR_NEXT_ITEM_MS {1500}

Detailed Description

template<int Pri = 0>
requires ((Pri >= -10) && (Pri <= 10))
struct siddiqsoft::periodic_worker< Pri >

Implements a simple queue + semaphore driven asynchronous processor.

Template Parameters
TThe data type for this processor
PriOptional thread priority level. 0=Normal

Definition at line 71 of file periodic_worker.hpp.

Constructor & Destructor Documentation

◆ ~periodic_worker()

template<int Pri = 0>
siddiqsoft::periodic_worker< Pri >::~periodic_worker ( )
inline

Destructor Cancel the semaphore by first resetting the interval to zero. Signal the semaphore follow that by requesting thread to stop. This is slightly better than allowing the default destructors to kick in If we do not reduce the interval time and signal a release then the timeout might be quite large! If the callback hangs and does not properly check for the stop_token then we end up with a locked periodic_worker without a neat way to terminate.

Definition at line 93 of file periodic_worker.hpp.

◆ periodic_worker()

template<int Pri = 0>
siddiqsoft::periodic_worker< Pri >::periodic_worker ( std::function< void()> c,
std::chrono::microseconds interval,
std::string name = {"anonymous-periodic-worker"} )
inline

Constructor requires the callback for the thread.

Parameters
cThe callback which accepts the type T as reference and performs action.
intervalThe interval between each invocation

Definition at line 170 of file periodic_worker.hpp.

Member Function Documentation

◆ forceCleanupTerminate()

template<int Pri = 0>
void siddiqsoft::periodic_worker< Pri >::forceCleanupTerminate ( const std::source_location & sl = std::source_location::current())
inline

This method is to be used by the user when they shutdown their application. This is best used for cases when the callback cannot be guaranteed to be "clean" or respect the stop_token.

Definition at line 133 of file periodic_worker.hpp.

Member Data Documentation

◆ DEFAULT_WAIT_FOR_NEXT_ITEM_MS

template<int Pri = 0>
std::chrono::milliseconds siddiqsoft::periodic_worker< Pri >::DEFAULT_WAIT_FOR_NEXT_ITEM_MS {1500}
staticconstexpr

Definition at line 73 of file periodic_worker.hpp.


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