feat: ETLng loader basics (#1808)

For #1597
This commit is contained in:
Alex Kremer
2025-01-09 14:47:08 +00:00
committed by GitHub
parent 36a9f40a60
commit 48c8d85d0c
31 changed files with 1093 additions and 36 deletions

View File

@@ -26,6 +26,7 @@ Repeat::stop()
{
if (control_->stopping)
return;
control_->stopping = true;
control_->timer.cancel();
control_->semaphore.acquire();

View File

@@ -30,6 +30,7 @@
#include <concepts>
#include <memory>
#include <semaphore>
#include <utility>
namespace util {
@@ -48,7 +49,7 @@ class Repeat {
}
};
std::unique_ptr<Control> control_;
std::shared_ptr<Control> control_;
public:
/**
@@ -89,23 +90,23 @@ public:
{
ASSERT(control_->stopping, "Should be stopped before starting");
control_->stopping = false;
startImpl(interval, std::forward<Action>(action));
startImpl(control_, interval, std::forward<Action>(action));
}
private:
template <std::invocable Action>
void
startImpl(std::chrono::steady_clock::duration interval, Action&& action)
static void
startImpl(std::shared_ptr<Control> control, std::chrono::steady_clock::duration interval, Action&& action)
{
control_->timer.expires_after(interval);
control_->timer.async_wait([this, interval, action = std::forward<Action>(action)](auto const& ec) mutable {
if (ec or control_->stopping) {
control_->semaphore.release();
control->timer.expires_after(interval);
control->timer.async_wait([control, interval, action = std::forward<Action>(action)](auto const& ec) mutable {
if (ec or control->stopping) {
control->semaphore.release();
return;
}
action();
startImpl(interval, std::forward<Action>(action));
startImpl(std::move(control), interval, std::forward<Action>(action));
});
}
};

View File

@@ -24,6 +24,7 @@
#include <boost/asio/spawn.hpp>
#include <chrono>
#include <memory>
#include <type_traits>
#include <utility>

View File

@@ -19,8 +19,10 @@
#pragma once
#include <boost/asio/associated_executor.hpp>
#include <boost/asio/post.hpp>
#include <boost/asio/spawn.hpp>
#include <boost/asio/steady_timer.hpp>
#include <atomic>
#include <memory>