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:
Alex Kremer
2024-12-20 13:24:01 +00:00
committed by GitHub
parent f2a89b095d
commit 285d4e6e9b
17 changed files with 292 additions and 90 deletions

View File

@@ -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