feat: Async framework submit on strand/ctx (#2751)

This commit is contained in:
Alex Kremer
2025-11-04 19:14:31 +00:00
committed by GitHub
parent d6ab2cc1e4
commit 6d79dd6b2b
14 changed files with 296 additions and 110 deletions

View File

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