Fix coroutine suspend

This commit is contained in:
Tom Ritchford
2015-07-28 16:16:06 -04:00
committed by Nik Bougalis
parent fa0a61b5d7
commit 645e32b19e
3 changed files with 19 additions and 7 deletions

View File

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

View File

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

View File

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