mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Fix coroutine suspend
This commit is contained in:
committed by
Nik Bougalis
parent
fa0a61b5d7
commit
645e32b19e
@@ -47,6 +47,15 @@ struct Context
|
||||
NodeStore::ScopedMetrics metrics;
|
||||
};
|
||||
|
||||
inline
|
||||
void suspend(Context const& context, Continuation const& continuation)
|
||||
{
|
||||
if (context.suspend)
|
||||
context.suspend(continuation);
|
||||
else
|
||||
continuation(doNothingCallback);
|
||||
}
|
||||
|
||||
} // RPC
|
||||
} // ripple
|
||||
|
||||
|
||||
@@ -40,8 +40,9 @@ namespace RPC {
|
||||
/** Callback: do something and eventually return. */
|
||||
using Callback = std::function <void ()>;
|
||||
|
||||
/** A non-empty callback that does nothing. */
|
||||
static
|
||||
Callback const emptyCallback ([] () {});
|
||||
Callback const doNothingCallback ([] () {});
|
||||
|
||||
/** Continuation: do something, guarantee to eventually call Callback. */
|
||||
using Continuation = std::function <void (Callback const&)>;
|
||||
@@ -115,7 +116,7 @@ Callback suspendForContinuation (
|
||||
{
|
||||
return suspend
|
||||
? Callback ([=] () { suspend (continuation); })
|
||||
: emptyCallback;
|
||||
: Callback ([=] () { continuation (doNothingCallback); });
|
||||
}
|
||||
|
||||
} // RPC
|
||||
|
||||
@@ -104,13 +104,15 @@ Json::Value doRipplePathFind (RPC::Context& context)
|
||||
lpLedger = context.ledgerMaster.getClosedLedger();
|
||||
|
||||
PathRequest::pointer request;
|
||||
context.suspend ([&request, &context, &jvResult, &lpLedger]
|
||||
(RPC::Callback const& c)
|
||||
suspend(context,
|
||||
[&request, &context, &jvResult, &lpLedger]
|
||||
(RPC::Callback const& callback)
|
||||
{
|
||||
jvResult = getApp().getPathRequests().makeLegacyPathRequest (
|
||||
request, c, lpLedger, context.params);
|
||||
if (! request)
|
||||
c();
|
||||
request, callback, lpLedger, context.params);
|
||||
assert(callback);
|
||||
if (! request && callback)
|
||||
callback();
|
||||
});
|
||||
|
||||
if (request)
|
||||
|
||||
Reference in New Issue
Block a user