Commit 439c7b22 authored by Andrii Grynenko's avatar Andrii Grynenko Committed by Facebook GitHub Bot

Fix blockingWait to schedule task on the DrivableExecutor

Summary: The first portion of the task (before the first suspension point) was run inline.

Reviewed By: yfeldblum

Differential Revision: D21460275

fbshipit-source-id: 31d50e15d5890fbc7127dfff424a4e814dcb2320
parent 34ea33d2
......@@ -222,10 +222,11 @@ class BlockingWaitTask {
folly::Try<detail::lift_lvalue_reference_t<T>> result;
auto& promise = coro_.promise();
promise.setTry(&result);
{
RequestContextScopeGuard guard{RequestContext::saveContext()};
coro_.resume();
}
executor->add(
[coro = coro_, rctx = RequestContext::saveContext()]() mutable {
RequestContextScopeGuard guard{std::move(rctx)};
coro.resume();
});
while (!promise.done()) {
executor->drive();
}
......
......@@ -255,8 +255,13 @@ TEST_F(BlockingWaitTest, WaitTaskInFiber) {
auto& fm = folly::fibers::getFiberManager(evb);
auto future = fm.addTaskFuture([&] {
return folly::coro::blockingWait(folly::coro::co_invoke(
[&]() -> folly::coro::Task<int> { co_return co_await promise; }));
return folly::coro::blockingWait(
folly::coro::co_invoke([&]() -> folly::coro::Task<int> {
EXPECT_FALSE(folly::fibers::onFiber());
auto ret = co_await promise;
EXPECT_FALSE(folly::fibers::onFiber());
co_return ret;
}));
});
evb.loopOnce();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment