Commit c22c915d authored by Shai Szulanski's avatar Shai Szulanski Committed by Facebook GitHub Bot

Avoid throwing exceptions when using co_invoke

Summary: After D29680441 (https://github.com/facebook/folly/commit/832f135adede09d6e83e1f026c159d1b88249951) the Try path is as performant as the non-Try path on values for AsyncGenerator, and they're equivalent for Task.

Reviewed By: yfeldblum

Differential Revision: D29968047

fbshipit-source-id: 035355b64f94a3ef628c8f09b605c55956606bd1
parent 64711548
......@@ -349,8 +349,8 @@ class FOLLY_NODISCARD AsyncGenerator {
friend AsyncGenerator tag_invoke(
tag_t<co_invoke_fn>, tag_t<AsyncGenerator, F, A...>, F_ f, A_... a) {
auto r = invoke(static_cast<F&&>(f), static_cast<A&&>(a)...);
while (auto v = co_await r.next()) {
co_yield std::move(v).value();
while (true) {
co_yield co_result(co_await co_awaitTry(r.next()));
}
}
......
......@@ -624,7 +624,8 @@ class FOLLY_NODISCARD Task {
template <typename F, typename... A, typename F_, typename... A_>
friend Task tag_invoke(
tag_t<co_invoke_fn>, tag_t<Task, F, A...>, F_ f, A_... a) {
co_return co_await invoke(static_cast<F&&>(f), static_cast<A&&>(a)...);
co_yield co_result(co_await co_awaitTry(
invoke(static_cast<F&&>(f), static_cast<A&&>(a)...)));
}
private:
......
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