#pragma once
#include <folly/CancellationToken.h>
#include <folly/experimental/coro/Coroutine.h>
#include <folly/lang/CustomizationPoint.h>
#if FOLLY_HAS_COROUTINES
namespace folly {
namespace coro {
namespace detail {
namespace adl {
template <typename Awaitable>
Awaitable&& co_withCancellation(
const folly::CancellationToken&, Awaitable&& awaitable) noexcept {
return (Awaitable&&)awaitable;
}
struct WithCancellationFunction {
template <typename Awaitable>
auto operator()(
const folly::CancellationToken& cancelToken, Awaitable&& awaitable) const
noexcept(
noexcept(co_withCancellation(cancelToken, (Awaitable&&)awaitable)))
-> decltype(co_withCancellation(
cancelToken, (Awaitable&&)awaitable)) {
return co_withCancellation(cancelToken, (Awaitable&&)awaitable);
}
template <typename Awaitable>
auto operator()(folly::CancellationToken&& cancelToken, Awaitable&& awaitable)
const noexcept(noexcept(
co_withCancellation(std::move(cancelToken), (Awaitable&&)awaitable)))
-> decltype(co_withCancellation(
std::move(cancelToken), (Awaitable&&)awaitable)) {
return co_withCancellation(std::move(cancelToken), (Awaitable&&)awaitable);
}
};
}
}
FOLLY_DEFINE_CPO(detail::adl::WithCancellationFunction, co_withCancellation)
}
}
#endif