LibQuicR
quicr::Reply< T, E > Class Template Reference

The reply to a callback, which may be answered immediately or deferred. More...

#include <reply.h>

Public Types

using ResultType = Expected< T, Error< E > >
 Immediate success-or-error result represented by this reply. More...
 
using CompletionType = std::function< void(ResultType)>
 Continuation invoked with the completed result. More...
 
using DeferType = std::function< void(CompletionType &&)>
 Deferred producer that must invoke its completion exactly once. More...
 

Public Member Functions

 Reply ()=default
 Construct an immediate default result. More...
 
 Reply (const Reply &other)=delete
 Replies are move-only because resolving consumes their state. More...
 
 Reply (Reply &&other) noexcept=default
 Move a reply, transferring its unresolved result or deferred action. More...
 
Reply & operator= (const Reply &other)=delete
 Replies cannot be copy-assigned. More...
 
Reply & operator= (Reply &&other) noexcept=default
 Move-assign a reply, transferring its unresolved state. More...
 
template<typename U >
 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, or an Unexpected error. More...
 
template<typename F >
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. More...
 

Static Public Member Functions

static Reply Defer (DeferType &&action)
 Construct a reply whose producer may complete asynchronously. More...
 

Detailed Description

template<typename T, typename E>
class quicr::Reply< T, E >

The reply to a callback, which may be answered immediately or deferred.

A Reply either holds the callback result or a producer that receives a completion callback. Resolve() invokes a deferred producer synchronously on the calling thread. The producer must start any slow authorization, I/O, or other asynchronous work itself and invoke the completion later.

Template Parameters
TThe value type of a successful reply.
EThe reason code type of a failed reply.

Member Typedef Documentation

◆ CompletionType

template<typename T , typename E >
using quicr::Reply< T, E >::CompletionType = std::function<void(ResultType)>

Continuation invoked with the completed result.

◆ DeferType

template<typename T , typename E >
using quicr::Reply< T, E >::DeferType = std::function<void(CompletionType&&)>

Deferred producer that must invoke its completion exactly once.

◆ ResultType

template<typename T , typename E >
using quicr::Reply< T, E >::ResultType = Expected<T, Error<E> >

Immediate success-or-error result represented by this reply.

Constructor & Destructor Documentation

◆ Reply() [1/3]

template<typename T , typename E >
quicr::Reply< T, E >::Reply ( )
default

Construct an immediate default result.

◆ Reply() [2/3]

template<typename T , typename E >
quicr::Reply< T, E >::Reply ( const Reply< T, E > &  other)
delete

Replies are move-only because resolving consumes their state.

Parameters
otherReply that would be copied.

◆ Reply() [3/3]

template<typename T , typename E >
quicr::Reply< T, E >::Reply ( Reply< T, E > &&  other)
defaultnoexcept

Move a reply, transferring its unresolved result or deferred action.

Parameters
otherReply to move.

Member Function Documentation

◆ Defer()

template<typename T , typename E >
static Reply quicr::Reply< T, E >::Defer ( DeferType &&  action)
inlinestatic

Construct a reply whose producer may complete asynchronously.

The action owns the completion callback passed to it and must invoke that callback exactly once. The action itself is invoked synchronously by Resolve; it must arrange any desired off-thread work.

Parameters
actionProducer that eventually supplies the reply result.
Returns
A deferred reply owning action.

◆ operator=() [1/2]

template<typename T , typename E >
Reply& quicr::Reply< T, E >::operator= ( const Reply< T, E > &  other)
delete

Replies cannot be copy-assigned.

Parameters
otherReply that would be copied.

◆ operator=() [2/2]

template<typename T , typename E >
Reply& quicr::Reply< T, E >::operator= ( Reply< T, E > &&  other)
defaultnoexcept

Move-assign a reply, transferring its unresolved state.

Parameters
otherReply to move.
Returns
This reply.

◆ requires()

template<typename T , typename E >
template<typename U >
quicr::Reply< T, E >::requires ( !std::same_as< std::remove_cvref_t< U >, Reply< T, E > > &&std::is_constructible_v< ResultType, U && >  ) &&
inline

Construct an immediate reply from anything the result is constructible from, such as a value, or an Unexpected error.

Template Parameters
USource type used to construct ResultType.
Parameters
valueSuccessful value or unexpected error to store.

◆ Resolve()

template<typename T , typename E >
template<typename F >
void quicr::Reply< T, E >::Resolve ( const std::shared_ptr< Transport > &  transport,
F &&  f 
)
inline

Hand the result to the given continuation, either now or once the deferred action completes.

Immediate continuations run on the calling thread. A deferred completion is queued through transport and runs on the transport notification thread. Capturing the transport keeps it alive until completion is queued.

Template Parameters
FCallable accepting ResultType.
Parameters
transportTransport used to marshal a deferred completion to its notification thread; must remain usable and must not be null.
fContinuation invoked with the result.
Precondition
This reply has not previously been resolved.
Note
Consumes the stored state; resolving the same reply more than once is invalid.

The documentation for this class was generated from the following file: