Commit 8c7f9c00 authored by Lewis Baker's avatar Lewis Baker Committed by Facebook Github Bot

Add overload of blockingWait() that takes DrivableExecutor

Summary:
This allows the caller to, for example, pass their own ManualExecutor or EventBase
and have the task scheduled onto that executor and have the current thread drive
that executor until it completes.

Reviewed By: yfeldblum

Differential Revision: D19205803

fbshipit-source-id: 6042f68decf8d7d9bb1d37977e5804b0504daa41
parent d4d80f77
......@@ -359,19 +359,25 @@ auto blockingWait(Awaitable&& awaitable)
.get());
}
template <
typename SemiAwaitable,
std::enable_if_t<!is_awaitable_v<SemiAwaitable>, int> = 0>
auto blockingWait(SemiAwaitable&& awaitable)
template <typename SemiAwaitable>
auto blockingWait(SemiAwaitable&& awaitable, folly::DrivableExecutor* executor)
-> detail::decay_rvalue_reference_t<semi_await_result_t<SemiAwaitable>> {
detail::BlockingWaitExecutor executor;
return static_cast<
std::add_rvalue_reference_t<semi_await_result_t<SemiAwaitable>>>(
detail::makeRefBlockingWaitTask(
folly::coro::co_viaIfAsync(
folly::getKeepAliveToken(executor),
static_cast<SemiAwaitable&&>(awaitable)))
.getVia(&executor));
.getVia(executor));
}
template <
typename SemiAwaitable,
std::enable_if_t<!is_awaitable_v<SemiAwaitable>, int> = 0>
auto blockingWait(SemiAwaitable&& awaitable)
-> detail::decay_rvalue_reference_t<semi_await_result_t<SemiAwaitable>> {
detail::BlockingWaitExecutor executor;
return blockingWait(static_cast<SemiAwaitable&&>(awaitable), &executor);
}
} // namespace coro
......
......@@ -20,6 +20,7 @@
#include <folly/Optional.h>
#include <folly/ScopeGuard.h>
#include <folly/executors/ManualExecutor.h>
#include <folly/experimental/coro/Baton.h>
#include <folly/experimental/coro/BlockingWait.h>
#include <folly/experimental/coro/Invoke.h>
......@@ -289,4 +290,15 @@ TEST_F(BlockingWaitTest, RequestContext) {
EXPECT_EQ(ctx1.get(), folly::RequestContext::get());
}
TEST_F(BlockingWaitTest, DrivableExecutor) {
folly::ManualExecutor executor;
folly::coro::blockingWait(
[&]() -> folly::coro::Task<void> {
folly::Executor* taskExecutor =
co_await folly::coro::co_current_executor;
EXPECT_EQ(&executor, taskExecutor);
}(),
&executor);
}
#endif
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