mirror of
https://github.com/XRPLF/clio.git
synced 2026-06-06 10:16:42 +00:00
feat: Async framework submit on strand/ctx (#2751)
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "util/Assert.hpp"
|
||||
#include "util/async/Concepts.hpp"
|
||||
#include "util/async/Error.hpp"
|
||||
|
||||
@@ -38,7 +39,7 @@ struct DefaultErrorHandler {
|
||||
return
|
||||
[fn = std::forward<decltype(fn)>(fn)]<typename... Args>(SomeOutcome auto& outcome, Args&&... args) mutable {
|
||||
try {
|
||||
fn(outcome, std::forward<Args>(args)...);
|
||||
std::invoke(std::forward<decltype(fn)>(fn), outcome, std::forward<Args>(args)...);
|
||||
} catch (std::exception const& e) {
|
||||
outcome.setValue(
|
||||
std::unexpected(ExecutionError{fmt::format("{}", std::this_thread::get_id()), e.what()})
|
||||
@@ -50,6 +51,20 @@ struct DefaultErrorHandler {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
[[nodiscard]] static auto
|
||||
catchAndAssert(auto&& fn) noexcept // note this is a lie when used with MockAssert (use MockAssertNoThrow)
|
||||
{
|
||||
return [fn = std::forward<decltype(fn)>(fn)] mutable {
|
||||
try {
|
||||
std::invoke(std::forward<decltype(fn)>(fn));
|
||||
} catch (std::exception const& e) {
|
||||
ASSERT(false, "Exception caught: {}", e.what());
|
||||
} catch (...) {
|
||||
ASSERT(false, "Unknown exception caught");
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
struct NoErrorHandler {
|
||||
@@ -58,6 +73,12 @@ struct NoErrorHandler {
|
||||
{
|
||||
return std::forward<decltype(fn)>(fn);
|
||||
}
|
||||
|
||||
[[nodiscard]] static constexpr auto
|
||||
catchAndAssert(auto&& fn)
|
||||
{
|
||||
return std::forward<decltype(fn)>(fn);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace util::async::impl
|
||||
|
||||
Reference in New Issue
Block a user