|
xrpld
|

Directories | |
| detail | |
| handlers | |
Files | |
| BookChanges.h | |
| Context.h | |
| CTID.h | |
| DeliveredAmount.h | |
| GRPCHandlers.h | |
| json_body.h | |
| MPTokenIssuanceID.h | |
| Output.h | |
| Role.h | |
| RPCCall.h | |
| RPCHandler.h | |
| RPCSub.h | |
| ServerHandler.h | |
| Status.h | |
By default, an RPC handler runs as an uninterrupted task on the JobQueue. This is fine for commands that are fast to compute but might not be acceptable for tasks that require multiple parts or are large, like a full ledger.
For this purpose, the xrpld RPC handler allows suspension with continuation
Suspension with continuation uses four std::functions in the xrpl::RPC namespace:
using Callback = std::function <void ()>; using Continuation = std::function <void (Callback const&)>; using Suspend = std::function <void (Continuation const&)>; using Coroutine = std::function <void (Suspend const&)>;
A Callback is a generic 0-argument function. A given Callback might or might not block. Unless otherwise advised, do not hold locks or any resource that would prevent any other task from making forward progress when you call a Callback.
A Continuation is a function that is given a Callback and promises to call it later. A Continuation guarantees to call the Callback exactly once at some point in the future, but it does not have to be immediately or even in the current thread.
A Suspend is a function belonging to a Coroutine. A Suspend runs a Continuation, passing it a Callback that continues execution of the Coroutine.
And finally, a Coroutine is a std::function which is given a Suspend. This is what the RPC handler gives to the coroutine manager, expecting to get called back with a Suspend and to be able to start execution.
Given these functions, the flow of RPC control when using coroutines is straight-forward.