rippled
Loading...
Searching...
No Matches
Spawn.h
1#ifndef XRPL_SERVER_SPAWN_H_INCLUDED
2#define XRPL_SERVER_SPAWN_H_INCLUDED
3
4#include <xrpl/basics/Log.h>
5
6#include <boost/asio/spawn.hpp>
7#include <boost/asio/strand.hpp>
8
9#include <concepts>
10#include <type_traits>
11
12namespace ripple::util {
13namespace impl {
14
15template <typename T>
18 boost::asio::strand<typename std::decay_t<T>::inner_executor_type>>;
19
30inline constexpr auto kPROPAGATE_EXCEPTIONS = [](std::exception_ptr ePtr) {
31 if (ePtr)
32 {
33 try
34 {
36 }
37 catch (std::exception const& e)
38 {
39 JLOG(debugLog().warn()) << "Spawn exception: " << e.what();
40 throw;
41 }
42 catch (...)
43 {
44 JLOG(debugLog().warn()) << "Spawn exception: Unknown";
45 throw;
46 }
47 }
48};
49
50} // namespace impl
51
65template <typename Ctx, typename F>
67void
68spawn(Ctx&& ctx, F&& func)
69{
70 if constexpr (impl::IsStrand<Ctx>)
71 {
72 boost::asio::spawn(
74 std::forward<F>(func),
76 }
77 else
78 {
79 boost::asio::spawn(
80 boost::asio::make_strand(
81 boost::asio::get_associated_executor(std::forward<Ctx>(ctx))),
82 std::forward<F>(func),
84 }
85}
86
87} // namespace ripple::util
88
89#endif
T is_same_v
constexpr auto kPROPAGATE_EXCEPTIONS
A completion handler that restores boost::asio::spawn's behaviour from Boost 1.83.
Definition Spawn.h:30
void spawn(Ctx &&ctx, F &&func)
Spawns a coroutine using boost::asio::spawn
Definition Spawn.h:68
beast::Journal debugLog()
Returns a debug journal.
Definition Log.cpp:457
T rethrow_exception(T... args)
T what(T... args)