Always use co-routines:

This permits RPC handlers to suspend and reschedule:
This commit is contained in:
JoelKatz
2015-06-17 12:39:28 -07:00
committed by Vinnie Falco
parent 48d6a4ab6a
commit 3d6e76046c
3 changed files with 6 additions and 26 deletions

View File

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

View File

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

View File

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