mirror of
https://github.com/Xahau/xahaud.git
synced 2025-11-26 21:45:50 +00:00
Always use co-routines:
This permits RPC handlers to suspend and reschedule:
This commit is contained in:
@@ -78,15 +78,10 @@ private:
|
||||
struct YieldStrategy
|
||||
{
|
||||
enum class Streaming {no, yes};
|
||||
enum class UseCoroutines {no, yes};
|
||||
|
||||
/** Is the data streamed, or generated monolithically? */
|
||||
Streaming streaming = Streaming::no;
|
||||
|
||||
/** Are results generated in a coroutine? If this is no, then the code can
|
||||
never yield. */
|
||||
UseCoroutines useCoroutines = UseCoroutines::no;
|
||||
|
||||
/** How many bytes do we emit before yielding? 0 means "never yield due to
|
||||
number of bytes sent". */
|
||||
std::size_t byteYieldCount = 0;
|
||||
|
||||
@@ -70,9 +70,6 @@ YieldStrategy makeYieldStrategy (Section const& s)
|
||||
ys.streaming = get<bool> (s, "streaming") ?
|
||||
YieldStrategy::Streaming::yes :
|
||||
YieldStrategy::Streaming::no;
|
||||
ys.useCoroutines = get<bool> (s, "use_coroutines") ?
|
||||
YieldStrategy::UseCoroutines::yes :
|
||||
YieldStrategy::UseCoroutines::no;
|
||||
ys.byteYieldCount = get<std::size_t> (s, "byte_yield_count");
|
||||
ys.accountYieldCount = get<std::size_t> (s, "account_yield_count");
|
||||
ys.transactionYieldCount = get<std::size_t> (s, "transaction_yield_count");
|
||||
|
||||
@@ -181,24 +181,12 @@ ServerHandlerImp::onRequest (HTTP::Session& session)
|
||||
|
||||
auto detach = session.detach();
|
||||
|
||||
if (setup_.yieldStrategy.useCoroutines ==
|
||||
RPC::YieldStrategy::UseCoroutines::yes)
|
||||
{
|
||||
RPC::SuspendCallback suspend (
|
||||
[this, detach] (RPC::Suspend const& suspend) {
|
||||
processSession (detach, suspend);
|
||||
});
|
||||
RPC::Coroutine coroutine (suspend);
|
||||
coroutine.run();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_jobQueue.addJob (
|
||||
jtCLIENT, "RPC-Client",
|
||||
[=] (Job&) {
|
||||
processSession (detach, RPC::Suspend());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
Reference in New Issue
Block a user