A class to repeat some action at a regular interval.
More...
#include <Repeat.hpp>
|
| Repeat (auto &ctx) |
| Construct a new Repeat object.
|
|
| Repeat (Repeat const &)=delete |
|
Repeat & | operator= (Repeat const &)=delete |
|
| Repeat (Repeat &&)=default |
|
Repeat & | operator= (Repeat &&)=default |
|
void | stop () |
| Stop repeating.
|
|
template<std::invocable Action> |
void | start (std::chrono::steady_clock::duration interval, Action &&action) |
| Start asynchronously repeating.
|
|
A class to repeat some action at a regular interval.
- Note
- io_context must be stopped before the Repeat object is destroyed. Otherwise it is undefined behavior
◆ Repeat()
util::Repeat::Repeat |
( |
auto & | ctx | ) |
|
|
inline |
Construct a new Repeat object.
- Note
- The
ctx
parameter is auto
so that this util supports strand
and thread_pool
as well as io_context
- Parameters
-
ctx | The io_context-like object to use |
◆ start()
template<std::invocable Action>
void util::Repeat::start |
( |
std::chrono::steady_clock::duration | interval, |
|
|
Action && | action ) |
|
inline |
Start asynchronously repeating.
- Note
- stop() must be called before start() is called for the second time
- Template Parameters
-
- Parameters
-
interval | The interval to repeat |
action | The action to call regularly |
◆ stop()
void util::Repeat::stop |
( |
| ) |
|
Stop repeating.
- Note
- This method will block to ensure the repeating is actually stopped. But blocking time should be very short.
The documentation for this class was generated from the following files:
- /__w/clio/clio/src/util/Repeat.hpp
- /__w/clio/clio/src/util/Repeat.cpp