Commit 4485ef0c authored by Pranav Thulasiram Bhat's avatar Pranav Thulasiram Bhat Committed by Facebook GitHub Bot

FiberManager - executeOnFiber

Summary:
This diff implements a new API to schedule a function on a new fiber and block the existing fiber till completion.

The API should be used sparingly to deal with fiber-stack-overflow issues

Reviewed By: A5he

Differential Revision: D22074021

fbshipit-source-id: 893e578b1acd6dd5cca34187fc8431202cdb73da
parent ac28a012
......@@ -83,6 +83,19 @@ collectAll(Ts&&... tasks) {
return Async(folly::unwrapTryTuple(std::move(tuple)));
}
/*
* Run an async-annotated functor on a new fiber, blocking the current fiber.
*
* Should be used sparingly to reset the fiber stack usage and avoid fiber stack
* overflows
*/
template <typename F>
auto executeOnNewFiber(F&& func) {
DCHECK(detail::onFiber());
return futureWait(detail::addFiberFuture(
std::forward<F>(func), FiberManager::getFiberManager()));
}
} // namespace async
} // namespace fibers
} // namespace folly
......
......@@ -259,12 +259,18 @@ TEST(FiberManager, asyncFiberManager) {
}
{
bool completed = false;
bool outerCompleted = false;
async::executeOnFiberAndWait([&]() -> async::Async<void> {
completed = true;
bool innerCompleted = false;
async::await(async::executeOnNewFiber([&]() -> async::Async<void> {
innerCompleted = true;
return {};
}));
EXPECT_TRUE(innerCompleted);
outerCompleted = true;
return {};
});
EXPECT_TRUE(completed);
EXPECT_TRUE(outerCompleted);
}
{
......
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