xrpld
Loading...
Searching...
No Matches
include
xrpl
server
detail
Spawn.h
1
#pragma once
2
3
#include <xrpl/basics/Log.h>
4
5
#include <boost/asio/spawn.hpp>
6
#include <boost/asio/strand.hpp>
7
8
#include <
concepts
>
9
#include <
type_traits
>
10
11
namespace
xrpl::util
{
12
namespace
impl
{
13
14
template
<
typename
T>
15
concept
IsStrand
= std::
16
same_as<std::decay_t<T>, boost::asio::strand<typename std::decay_t<T>::inner_executor_type>>;
17
28
inline
constexpr
auto
kPropagateExceptions
= [](
std::exception_ptr
ePtr) {
29
if
(ePtr)
30
{
31
try
32
{
33
std::rethrow_exception
(ePtr);
34
}
35
catch
(
std::exception
const
& e)
36
{
37
JLOG(
debugLog
().warn()) <<
"Spawn exception: "
<< e.
what
();
38
throw
;
39
}
40
catch
(...)
41
{
42
JLOG(
debugLog
().warn()) <<
"Spawn exception: Unknown"
;
43
throw
;
44
}
45
}
46
};
47
48
}
// namespace impl
49
63
template
<
typename
Ctx,
typename
F>
64
requires
std::is_invocable_r_v<void, F, boost::asio::yield_context>
65
void
66
spawn
(Ctx&& ctx, F&& func)
67
{
68
if
constexpr
(
impl::IsStrand<Ctx>
)
69
{
70
boost::asio::spawn(
71
std::forward<Ctx>
(ctx),
std::forward<F>
(func),
impl::kPropagateExceptions
);
72
}
73
else
74
{
75
boost::asio::spawn(
76
boost::asio::make_strand(boost::asio::get_associated_executor(
std::forward<Ctx>
(ctx))),
77
std::forward<F>
(func),
78
impl::kPropagateExceptions
);
79
}
80
}
81
82
}
// namespace xrpl::util
concepts
xrpl::util::impl::IsStrand
Definition
Spawn.h:15
std::exception
std::exception_ptr
std::forward
T forward(T... args)
std::is_invocable_r_v
T is_invocable_r_v
xrpl::util::impl
Definition
Spawn.h:12
xrpl::util::impl::kPropagateExceptions
constexpr auto kPropagateExceptions
A completion handler that restores boost::asio::spawn's behaviour from Boost 1.83.
Definition
Spawn.h:28
xrpl::util
Definition
Spawn.h:11
xrpl::util::spawn
void spawn(Ctx &&ctx, F &&func)
Spawns a coroutine using boost::asio::spawn.
Definition
Spawn.h:66
xrpl::debugLog
beast::Journal debugLog()
Returns a debug journal.
Definition
Log.cpp:399
std::rethrow_exception
T rethrow_exception(T... args)
type_traits
std::exception::what
T what(T... args)
Generated by
1.16.1