diff --git a/folly/coro/BUCK b/folly/coro/BUCK index 4b61e366abe..8944ca4f58e 100644 --- a/folly/coro/BUCK +++ b/folly/coro/BUCK @@ -96,6 +96,7 @@ cpp_library( "//folly/synchronization:atomic_util", ], exported_deps = [ + "//folly:try", "//folly/experimental/coro:coroutine", ], ) diff --git a/folly/coro/Baton.h b/folly/coro/Baton.h index 43b67e7a6f8..557e135c98f 100644 --- a/folly/coro/Baton.h +++ b/folly/coro/Baton.h @@ -18,6 +18,7 @@ #include +#include #include #if FOLLY_HAS_COROUTINES @@ -107,6 +108,10 @@ class Baton { void await_resume() noexcept {} + // Awaiting a baton doesn't throw, so supporting `co_awaitTry` here only + // serves to simplify generic code. + folly::Try await_resume_try() noexcept { return {}; } + protected: friend class Baton; diff --git a/folly/coro/test/BatonTest.cpp b/folly/coro/test/BatonTest.cpp index 0292357e8e4..3cc9995496d 100644 --- a/folly/coro/test/BatonTest.cpp +++ b/folly/coro/test/BatonTest.cpp @@ -90,7 +90,8 @@ TEST_F(BatonTest, MultiAwaitBaton) { auto makeTask2 = [&]() -> coro::Task { reachedBeforeAwait2 = true; - co_await baton; + // Equivalent to `co_await baton`, we just want it to compile. + co_await co_awaitTry(baton.operator co_await()); reachedAfterAwait2 = true; };