diff options
author | HÃ¥vard Pettersen <3535158+havardpe@users.noreply.github.com> | 2023-02-15 14:54:44 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-15 14:54:44 +0100 |
commit | 1742d97a1a17276f3d89216593a1d0906e73f8a4 (patch) | |
tree | 9a73e51556b671bc630d495f6e753150b10d8f30 | |
parent | 11806f941593d6f7c4b7c5eacfbf9497e60505ca (diff) | |
parent | 6e0f28394c5c50d1afbb024bff780d1ace185008 (diff) |
Merge pull request #26045 from vespa-engine/havardpe/better-start-async-concept
use single concept for start async op functions
-rw-r--r-- | vespalib/src/vespa/vespalib/coro/waiting_for.h | 30 |
1 files changed, 10 insertions, 20 deletions
diff --git a/vespalib/src/vespa/vespalib/coro/waiting_for.h b/vespalib/src/vespa/vespalib/coro/waiting_for.h index 7ded6211200..b9edbd7c8ff 100644 --- a/vespalib/src/vespa/vespalib/coro/waiting_for.h +++ b/vespalib/src/vespa/vespalib/coro/waiting_for.h @@ -102,26 +102,16 @@ static_assert(receiver_of<WaitingFor<std::unique_ptr<int>>, std::unique_ptr<int> // concept indicating that F is a function that starts an async // operation with T as result. The result will eventually be delivered -// to the WaitingFor<T> passed to the function. +// to the WaitingFor<T> passed to the function. This function has +// optional support for symmetric transfer to switch to another +// coroutine as a side-effect of starting the async operation. This +// also enables the function to change the operation form async to +// sync by setting the value directly in the function and returning +// wf.mu() template <typename F, typename T> -concept start_async_op = requires(F &&f, std::decay_t<F> cpy, WaitingFor<T> wf) { - std::decay_t<F>(std::forward<F>(f)); - { cpy(std::move(wf)) } -> std::same_as<void>; -}; - -// concept indicating that F is a function that starts an async -// operation with T as result. The result will eventually be delivered -// to the WaitingFor<T> passed to the function. This variant will use -// symmetric transfer to switch to another coroutine as a side-effect -// of starting the async operation (and thus suspending the -// coroutine). This also enables the function to change the operation -// form async to sync by setting the value directly in the function -// and returning wf.mu() -template <typename F, typename T> -concept maybe_start_async_op = requires(F &&f, std::decay_t<F> cpy, WaitingFor<T> wf) { - std::decay_t<F>(std::forward<F>(f)); - { cpy(std::move(wf)) } -> std::same_as<std::coroutine_handle<>>; -}; +concept start_async_op = requires(F &&f) { std::decay_t<F>(std::forward<F>(f)); } && +(requires(std::decay_t<F> cpy, WaitingFor<T> wf) { { cpy(std::move(wf)) } -> std::same_as<void>; } || + requires(std::decay_t<F> cpy, WaitingFor<T> wf) { { cpy(std::move(wf)) } -> std::same_as<std::coroutine_handle<>>; }); // Create a custom awaiter that will return a value of type T when the // coroutine is resumed. The operation waited upon is represented by @@ -133,7 +123,7 @@ concept maybe_start_async_op = requires(F &&f, std::decay_t<F> cpy, WaitingFor<T // await_resume must return T by value, since the awaiter containing // the result is a temporary object. template <typename T, typename F> -requires start_async_op<F,T> || maybe_start_async_op<F,T> +requires start_async_op<F,T> auto wait_for(F &&on_suspend) { struct awaiter final : PromiseState<T> { using PromiseState<T>::result; |