Clio develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
util::Repeat Class Reference

A class to repeat some action at a regular interval. More...

#include <Repeat.hpp>

Public Member Functions

 Repeat (auto &ctx)
 Construct a new Repeat object.
 
 Repeat (Repeat const &)=delete
 
Repeatoperator= (Repeat const &)=delete
 
 Repeat (Repeat &&)=default
 
Repeatoperator= (Repeat &&)=default
 
void stop ()
 Stop repeating.
 
template<std::invocable Action>
void start (std::chrono::steady_clock::duration interval, Action &&action)
 Start asynchronously repeating.
 

Detailed Description

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

Constructor & Destructor Documentation

◆ 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
ctxThe io_context-like object to use

Member Function Documentation

◆ 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
ActionThe action type
Parameters
intervalThe interval to repeat
actionThe 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: