Commit c39b0c3b authored by Qinfan Wu's avatar Qinfan Wu Committed by Facebook Github Bot

Let all Promise<T> be friend of Task

Summary:
[Folly][coro] Let all `Promise<T>` be friend of `Task`.

The code would not compile:

```lang=c++
coro::Task<void> taskVoid() {
  co_await task42();
  co_return;
}
```

```
folly/experimental/coro/Promise.h:84:28: error: 'viaInline' is a private member of 'folly::coro::Task<int>'
    return std::move(task).viaInline(executor_);
                           ^
folly/experimental/coro/tests/CoroTest.cpp:40:3: note: in instantiation of function template specialization 'folly::coro::Promise<void>::await_transform<int>' requested here
  co_await task42();
  ^
folly/experimental/coro/Task.h:60:13: note: declared private here
  Future<T> viaInline(folly::Executor* executor) && {
            ^
```

Reviewed By: andriigrynenko

Differential Revision: D7178238

fbshipit-source-id: 7dca6834ac56f4c9bdb4d702996b51e932f2aae6
parent d455cfc4
...@@ -53,7 +53,8 @@ class Task { ...@@ -53,7 +53,8 @@ class Task {
} }
private: private:
friend promise_type; template <typename U>
friend class Promise;
Future<T> viaInline(folly::Executor* executor) && { Future<T> viaInline(folly::Executor* executor) && {
promise_->executor_ = executor; promise_->executor_ = executor;
......
...@@ -36,6 +36,22 @@ TEST(Coro, Basic) { ...@@ -36,6 +36,22 @@ TEST(Coro, Basic) {
EXPECT_EQ(42, future.get()); EXPECT_EQ(42, future.get());
} }
coro::Task<void> taskVoid() {
co_await task42();
co_return;
}
TEST(Coro, Basic2) {
ManualExecutor executor;
auto future = taskVoid().via(&executor);
EXPECT_FALSE(future.await_ready());
executor.drive();
EXPECT_TRUE(future.await_ready());
}
coro::Task<void> taskSleep() { coro::Task<void> taskSleep() {
co_await futures::sleep(std::chrono::seconds{1}); co_await futures::sleep(std::chrono::seconds{1});
co_return; co_return;
......
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