Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

defer (7 of 7 overloads)

Submits a function to be run on a specified execution context, and passes the result to a completion handler.

template<
    typename Function,
    typename ExecutionContext,
    typename CompletionToken = default_completion_token_t<typename ExecutionContext::executor_type>>
auto defer(
    Function && function,
    ExecutionContext & ctx,
    CompletionToken && token = default_completion_token_t< typename ExecutionContext::executor_type >(),
    constraint_t< !is_void< result_of_t< decay_t< Function >()> >::value >  = 0,
    constraint_t< is_convertible< ExecutionContext &, execution_context & >::value >  = 0);
Parameters

function

A nullary function to be executed on the target executor.

ctx

An execution context, from which the target executor is obtained.

token

The completion token that will be used to produce a completion handler. The function signature of the completion handler must be:

void handler();
Return Value

defer(forward<Function>(function), ctx.get_executor(), forward<CompletionToken>(token)).

Remarks

If the function object throws an exception, that exception is allowed to propagate to the target executor. The behaviour in this case is dependent on the executor. For example, io_context will allow the exception to propagate to the caller that runs the io_context, whereas thread_pool will call std::terminate.

Completion Signature
void(decay_t<result_of_t<decay_t<Function>()>>)

PrevUpHomeNext