Commit 85b28533 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook GitHub Bot

let co_invoke be defined in terms of tag_invoke

Summary: Currently there is an extension point `folly_co_invoke` for providing customizations for `co_invoke`. But `tag_invoke` is intended as a generic mechanism for providing namespaced customizations. So let us use that.

Reviewed By: ericniebler

Differential Revision: D26674580

fbshipit-source-id: b1baea04996f162699510c3aba8d2c330fcf34bb
parent b58b2ce0
...@@ -572,8 +572,8 @@ class FOLLY_NODISCARD AsyncGenerator { ...@@ -572,8 +572,8 @@ class FOLLY_NODISCARD AsyncGenerator {
} }
template <typename F, typename... A, typename F_, typename... A_> template <typename F, typename... A, typename F_, typename... A_>
friend AsyncGenerator folly_co_invoke( friend AsyncGenerator tag_invoke(
tag_t<AsyncGenerator, F, A...>, F_ f, A_... a) { tag_t<co_invoke_type>, tag_t<AsyncGenerator, F, A...>, F_ f, A_... a) {
auto r = invoke(static_cast<F&&>(f), static_cast<A&&>(a)...); auto r = invoke(static_cast<F&&>(f), static_cast<A&&>(a)...);
while (auto v = co_await r.next()) { while (auto v = co_await r.next()) {
co_yield std::move(v).value(); co_yield std::move(v).value();
......
...@@ -255,7 +255,8 @@ class Generator { ...@@ -255,7 +255,8 @@ class Generator {
} }
template <typename F, typename... A, typename F_, typename... A_> template <typename F, typename... A, typename F_, typename... A_>
friend Generator folly_co_invoke(tag_t<Generator, F, A...>, F_ f, A_... a) { friend Generator tag_invoke(
tag_t<co_invoke_type>, tag_t<Generator, F, A...>, F_ f, A_... a) {
auto&& r = invoke(static_cast<F&&>(f), static_cast<A&&>(a)...); auto&& r = invoke(static_cast<F&&>(f), static_cast<A&&>(a)...);
for (auto&& v : r) { for (auto&& v : r) {
co_yield std::move(v); co_yield std::move(v);
......
...@@ -22,10 +22,6 @@ ...@@ -22,10 +22,6 @@
namespace folly { namespace folly {
namespace coro { namespace coro {
namespace invoke_detail {
void folly_co_invoke(folly::detail::invoke_private_overload&);
}
// co_invoke // co_invoke
// //
// This utility callable is a safe way to instantiate a coroutine using a // This utility callable is a safe way to instantiate a coroutine using a
...@@ -80,15 +76,18 @@ void folly_co_invoke(folly::detail::invoke_private_overload&); ...@@ -80,15 +76,18 @@ void folly_co_invoke(folly::detail::invoke_private_overload&);
struct co_invoke_type { struct co_invoke_type {
template <typename F, typename... A> template <typename F, typename... A>
FOLLY_ERASE constexpr auto operator()(F&& f, A&&... a) const FOLLY_ERASE constexpr auto operator()(F&& f, A&&... a) const
noexcept(noexcept(folly_co_invoke( noexcept(noexcept(tag_invoke(
tag<co_invoke_type>,
tag<invoke_result_t<F, A...>, F, A...>, tag<invoke_result_t<F, A...>, F, A...>,
static_cast<F&&>(f), static_cast<F&&>(f),
static_cast<A&&>(a)...))) static_cast<A&&>(a)...)))
-> decltype(folly_co_invoke( -> decltype(tag_invoke(
tag<co_invoke_type>,
tag<invoke_result_t<F, A...>, F, A...>, tag<invoke_result_t<F, A...>, F, A...>,
static_cast<F&&>(f), static_cast<F&&>(f),
static_cast<A&&>(a)...)) { static_cast<A&&>(a)...)) {
return folly_co_invoke( return tag_invoke(
tag<co_invoke_type>,
tag<invoke_result_t<F, A...>, F, A...>, tag<invoke_result_t<F, A...>, F, A...>,
static_cast<F&&>(f), static_cast<F&&>(f),
static_cast<A&&>(a)...); static_cast<A&&>(a)...);
......
...@@ -629,7 +629,8 @@ class FOLLY_NODISCARD Task { ...@@ -629,7 +629,8 @@ class FOLLY_NODISCARD Task {
} }
template <typename F, typename... A, typename F_, typename... A_> template <typename F, typename... A, typename F_, typename... A_>
friend Task folly_co_invoke(tag_t<Task, F, A...>, F_ f, A_... a) { friend Task tag_invoke(
tag_t<co_invoke_type>, tag_t<Task, F, A...>, F_ f, A_... a) {
co_return co_await invoke(static_cast<F&&>(f), static_cast<A&&>(a)...); co_return co_await invoke(static_cast<F&&>(f), static_cast<A&&>(a)...);
} }
......
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