Commit 8cf16b1e authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

Make co_current_executor look like nullptr, std::nullopt, std::in_place

Summary:
[Folly] Make `co_current_executor` look like `nullptr`, `std::nullopt`, `std::in_place`.

* Use a `co_` prefix to indicate that it is offers a useful result when awaited.
* Offer a well-named value with a well-named type or type alias.
  * There is the `nullptr` value and `std::nullptr_t` type or type alias.
  * There is the `std::nullopt` value and the `std::nullopt_t` type or type alias.
  * There is the `std::in_place` value and the `std::in_place_t` type or type alias.

Reviewed By: andriigrynenko, lewissbaker

Differential Revision: D13561713

fbshipit-source-id: 835da086e7165d37a952a1f169318cb566401d12
parent 1d5519da
......@@ -32,7 +32,16 @@
namespace folly {
namespace coro {
struct getCurrentExecutor {};
namespace detail {
struct co_current_executor_ {
enum class secret_ { token_ };
explicit constexpr co_current_executor_(secret_) {}
};
} // namespace detail
using co_current_executor_t = detail::co_current_executor_;
constexpr co_current_executor_t co_current_executor{
co_current_executor_t::secret_::token_};
template <typename T = void>
class Task;
......@@ -82,7 +91,7 @@ class TaskPromiseBase {
return co_viaIfAsync(executor_, static_cast<Awaitable&&>(awaitable));
}
auto await_transform(folly::coro::getCurrentExecutor) noexcept {
auto await_transform(co_current_executor_t) noexcept {
return AwaitableReady<folly::Executor*>{executor_};
}
......
......@@ -203,9 +203,9 @@ TEST(Coro, NestedThreads) {
}
coro::Task<int> taskGetCurrentExecutor(Executor* executor) {
auto currentExecutor = co_await coro::getCurrentExecutor();
EXPECT_EQ(executor, currentExecutor);
co_return co_await task42().scheduleOn(currentExecutor);
auto current = co_await coro::co_current_executor;
EXPECT_EQ(executor, current);
co_return co_await task42().scheduleOn(current);
}
TEST(Coro, CurrentExecutor) {
......
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