13 #include <type_traits>
29 template<
typename T,
typename E>
44 : result_(std::in_place_type<
DeferType>, std::move(action))
48 bool IsDeferred() const noexcept {
return std::holds_alternative<DeferType>(result_); }
79 requires(!std::same_as<std::remove_cvref_t<U>,
Reply> && std::is_constructible_v<ResultType, U &&>)
81 : result_(std::in_place_type<
ResultType>, std::forward<U>(value))
112 void Resolve(
const std::shared_ptr<Transport>& transport, F&& f)
115 auto action = std::move(std::get<DeferType>(result_));
116 action([transport, f = std::forward<F>(f)](
ResultType reply)
mutable {
117 transport->QueueDeferredReply(
118 [result = std::move(reply), f = std::forward<F>(f)]()
mutable { f(result); });
123 f(std::move(std::get<ResultType>(result_)));
127 std::variant<ResultType, DeferType> result_;
Holds either a success value or an error value.
Definition: expected.h:65
The reply to a callback, which may be answered immediately or deferred.
Definition: reply.h:31
static Reply Defer(DeferType &&action)
Construct a reply whose producer may complete asynchronously.
Definition: reply.h:95
void Resolve(const std::shared_ptr< Transport > &transport, F &&f)
Hand the result to the given continuation, either now or once the deferred action completes.
Definition: reply.h:112
Reply(Reply &&other) noexcept=default
Move a reply, transferring its unresolved result or deferred action.
Reply & operator=(Reply &&other) noexcept=default
Move-assign a reply, transferring its unresolved state.
Reply()=default
Construct an immediate default result.
std::function< void(ResultType)> CompletionType
Continuation invoked with the completed result.
Definition: reply.h:37
Reply & operator=(const Reply &other)=delete
Replies cannot be copy-assigned.
requires(!std::same_as< std::remove_cvref_t< U >, Reply > &&std::is_constructible_v< ResultType, U && >) Reply(U &&value)
Construct an immediate reply from anything the result is constructible from, such as a value,...
Definition: reply.h:79
std::function< void(CompletionType &&)> DeferType
Deferred producer that must invoke its completion exactly once.
Definition: reply.h:40
Reply(const Reply &other)=delete
Replies are move-only because resolving consumes their state.
Definition: attributes.h:13