mirror of
https://github.com/XRPLF/clio.git
synced 2026-06-06 18:26:47 +00:00
@@ -202,6 +202,24 @@ public:
|
||||
return pimpl_->makeStrand();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Stop the execution context
|
||||
*/
|
||||
void
|
||||
stop()
|
||||
{
|
||||
pimpl_->stop();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Join the execution context
|
||||
*/
|
||||
void
|
||||
join()
|
||||
{
|
||||
pimpl_->join();
|
||||
}
|
||||
|
||||
private:
|
||||
struct Concept {
|
||||
virtual ~Concept() = default;
|
||||
@@ -218,6 +236,10 @@ private:
|
||||
scheduleAfter(std::chrono::milliseconds, std::function<std::any(AnyStopToken, bool)>) = 0;
|
||||
virtual AnyStrand
|
||||
makeStrand() = 0;
|
||||
virtual void
|
||||
stop() = 0;
|
||||
virtual void
|
||||
join() = 0;
|
||||
};
|
||||
|
||||
template <typename CtxType>
|
||||
@@ -257,6 +279,18 @@ private:
|
||||
{
|
||||
return ctx.get().makeStrand();
|
||||
}
|
||||
|
||||
void
|
||||
stop() override
|
||||
{
|
||||
ctx.get().stop();
|
||||
}
|
||||
|
||||
void
|
||||
join() override
|
||||
{
|
||||
ctx.get().join();
|
||||
}
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "util/async/AnyStopToken.hpp"
|
||||
#include "util/async/Concepts.hpp"
|
||||
#include "util/async/impl/ErasedOperation.hpp"
|
||||
|
||||
#include <any>
|
||||
@@ -60,7 +59,7 @@ public:
|
||||
* @return The type-erased operation
|
||||
*/
|
||||
[[nodiscard]] auto
|
||||
execute(SomeHandlerWithoutStopToken auto&& fn)
|
||||
execute(SomeHandlerWithoutStopToken auto&& fn) const
|
||||
{
|
||||
using RetType = std::decay_t<decltype(fn())>;
|
||||
static_assert(not std::is_same_v<RetType, std::any>);
|
||||
@@ -84,7 +83,7 @@ public:
|
||||
* @return The type-erased operation
|
||||
*/
|
||||
[[nodiscard]] auto
|
||||
execute(SomeHandlerWith<AnyStopToken> auto&& fn)
|
||||
execute(SomeHandlerWith<AnyStopToken> auto&& fn) const
|
||||
{
|
||||
using RetType = std::decay_t<decltype(fn(std::declval<AnyStopToken>()))>;
|
||||
static_assert(not std::is_same_v<RetType, std::any>);
|
||||
@@ -109,7 +108,7 @@ public:
|
||||
* @return The type-erased operation
|
||||
*/
|
||||
[[nodiscard]] auto
|
||||
execute(SomeHandlerWith<AnyStopToken> auto&& fn, SomeStdDuration auto timeout)
|
||||
execute(SomeHandlerWith<AnyStopToken> auto&& fn, SomeStdDuration auto timeout) const
|
||||
{
|
||||
using RetType = std::decay_t<decltype(fn(std::declval<AnyStopToken>()))>;
|
||||
static_assert(not std::is_same_v<RetType, std::any>);
|
||||
@@ -134,11 +133,9 @@ private:
|
||||
virtual ~Concept() = default;
|
||||
|
||||
[[nodiscard]] virtual impl::ErasedOperation
|
||||
execute(
|
||||
std::function<std::any(AnyStopToken)>,
|
||||
std::optional<std::chrono::milliseconds> timeout = std::nullopt
|
||||
) = 0;
|
||||
[[nodiscard]] virtual impl::ErasedOperation execute(std::function<std::any()>) = 0;
|
||||
execute(std::function<std::any(AnyStopToken)>, std::optional<std::chrono::milliseconds> timeout = std::nullopt)
|
||||
const = 0;
|
||||
[[nodiscard]] virtual impl::ErasedOperation execute(std::function<std::any()>) const = 0;
|
||||
};
|
||||
|
||||
template <typename StrandType>
|
||||
@@ -152,13 +149,14 @@ private:
|
||||
}
|
||||
|
||||
[[nodiscard]] impl::ErasedOperation
|
||||
execute(std::function<std::any(AnyStopToken)> fn, std::optional<std::chrono::milliseconds> timeout) override
|
||||
execute(std::function<std::any(AnyStopToken)> fn, std::optional<std::chrono::milliseconds> timeout)
|
||||
const override
|
||||
{
|
||||
return strand.execute(std::move(fn), timeout);
|
||||
}
|
||||
|
||||
[[nodiscard]] impl::ErasedOperation
|
||||
execute(std::function<std::any()> fn) override
|
||||
execute(std::function<std::any()> fn) const override
|
||||
{
|
||||
return strand.execute(std::move(fn));
|
||||
}
|
||||
|
||||
@@ -327,6 +327,15 @@ public:
|
||||
{
|
||||
context_.executor.stop();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Block until all operations are completed
|
||||
*/
|
||||
void
|
||||
join() noexcept
|
||||
{
|
||||
context_.executor.join();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -40,6 +40,11 @@ struct SameThreadContext {
|
||||
stop() noexcept
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
join() noexcept
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
// Note: these types are not actually used but needed for compilation
|
||||
|
||||
@@ -64,10 +64,8 @@ public:
|
||||
BasicStrand(BasicStrand const&) = delete;
|
||||
|
||||
[[nodiscard]] auto
|
||||
execute(
|
||||
SomeHandlerWith<StopToken> auto&& fn,
|
||||
std::optional<std::chrono::milliseconds> timeout = std::nullopt
|
||||
) noexcept(isNoexcept)
|
||||
execute(SomeHandlerWith<StopToken> auto&& fn, std::optional<std::chrono::milliseconds> timeout = std::nullopt) const
|
||||
noexcept(isNoexcept)
|
||||
{
|
||||
return DispatcherType::dispatch(
|
||||
context_,
|
||||
@@ -91,7 +89,7 @@ public:
|
||||
}
|
||||
|
||||
[[nodiscard]] auto
|
||||
execute(SomeHandlerWith<StopToken> auto&& fn, SomeStdDuration auto timeout) noexcept(isNoexcept)
|
||||
execute(SomeHandlerWith<StopToken> auto&& fn, SomeStdDuration auto timeout) const noexcept(isNoexcept)
|
||||
{
|
||||
return execute(
|
||||
std::forward<decltype(fn)>(fn),
|
||||
@@ -100,7 +98,7 @@ public:
|
||||
}
|
||||
|
||||
[[nodiscard]] auto
|
||||
execute(SomeHandlerWithoutStopToken auto&& fn) noexcept(isNoexcept)
|
||||
execute(SomeHandlerWithoutStopToken auto&& fn) const noexcept(isNoexcept)
|
||||
{
|
||||
return DispatcherType::dispatch(
|
||||
context_,
|
||||
|
||||
Reference in New Issue
Block a user