mirror of
https://github.com/XRPLF/clio.git
synced 2026-06-04 17:26:49 +00:00
feat: Repeating operations for util::async (#1776)
Async framework needed a way to do repeating operations (think simplest cases like AmendmentBlockHandler). This PR implements the **absolute minimum**, barebones repeating operations that - Can't return any values (void) - Do not take any arguments in the user-provided function - Can't be scheduled (i.e. a delay before starting repeating) - Can't be stopped from inside the user block of code (i.e. does not have stop token or anything like that) - Can be stopped through the RepeatedOperation's `abort()` function (but not from the user-provided repeating function)
This commit is contained in:
@@ -19,24 +19,16 @@
|
||||
|
||||
#include "util/Repeat.hpp"
|
||||
|
||||
#include <boost/asio/io_context.hpp>
|
||||
|
||||
namespace util {
|
||||
|
||||
Repeat::Repeat(boost::asio::io_context& ioc) : timer_(ioc)
|
||||
{
|
||||
}
|
||||
|
||||
Repeat::~Repeat()
|
||||
{
|
||||
*stopped_ = true;
|
||||
}
|
||||
|
||||
void
|
||||
Repeat::stop()
|
||||
{
|
||||
*stopped_ = true;
|
||||
timer_.cancel();
|
||||
if (control_->stopping)
|
||||
return;
|
||||
control_->stopping = true;
|
||||
control_->timer.cancel();
|
||||
control_->semaphore.acquire();
|
||||
}
|
||||
|
||||
} // namespace util
|
||||
|
||||
Reference in New Issue
Block a user