|
asynchrony 0.0.0
Add asynchrony to your C++ applications using standard C++20
|
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} |
Implements a simple queue + semaphore driven asynchronous processor.
| T | The data type for this processor |
| Pri | Optional thread priority level. 0=Normal |
Definition at line 71 of file periodic_worker.hpp.
|
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.
|
inline |
Constructor requires the callback for the thread.
| c | The callback which accepts the type T as reference and performs action. |
| interval | The interval between each invocation |
Definition at line 170 of file periodic_worker.hpp.
|
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.
|
staticconstexpr |
Definition at line 73 of file periodic_worker.hpp.