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 <
exception
>
10
#include <
type_traits
>
11
12
namespace
xrpl::util
{
13
namespace
impl
{
14
15
template
<
typename
T>
16
concept
IsStrand
= std::
17
same_as<std::decay_t<T>, boost::asio::strand<typename std::decay_t<T>::inner_executor_type>>;
18
29
inline
constexpr
auto
kPropagateExceptions
= [](
std::exception_ptr
ePtr) {
30
if
(ePtr)
31
{
32
try
33
{
34
std::rethrow_exception
(ePtr);
35
}
36
catch
(
std::exception
const
& e)
37
{
38
JLOG(
debugLog
().warn()) <<
"Spawn exception: "
<< e.
what
();
39
throw
;
40
}
41
catch
(...)
42
{
43
JLOG(
debugLog
().warn()) <<
"Spawn exception: Unknown"
;
44
throw
;
45
}
46
}
47
};
48
49
}
// namespace impl
50
64
template
<
typename
Ctx,
typename
F>
65
requires
std::is_invocable_r_v<void, F, boost::asio::yield_context>
66
void
67
spawn
(Ctx&& ctx, F&& func)
68
{
69
if
constexpr
(
impl::IsStrand<Ctx>
)
70
{
71
boost::asio::spawn(
72
std::forward<Ctx>
(ctx),
std::forward<F>
(func),
impl::kPropagateExceptions
);
73
}
74
else
75
{
76
boost::asio::spawn(
77
boost::asio::make_strand(boost::asio::get_associated_executor(
std::forward<Ctx>
(ctx))),
78
std::forward<F>
(func),
79
impl::kPropagateExceptions
);
80
}
81
}
82
83
}
// namespace xrpl::util
concepts
xrpl::util::impl::IsStrand
Definition
Spawn.h:16
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:13
xrpl::util::impl::kPropagateExceptions
constexpr auto kPropagateExceptions
A completion handler that restores boost::asio::spawn's behaviour from Boost 1.83.
Definition
Spawn.h:29
xrpl::util
Definition
Spawn.h:12
xrpl::util::spawn
void spawn(Ctx &&ctx, F &&func)
Spawns a coroutine using boost::asio::spawn.
Definition
Spawn.h:67
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