// // defer.hpp // ~~~~~~~~~ // // Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #ifndef BOOST_ASIO_DEFER_HPP #define BOOST_ASIO_DEFER_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include #include #include #include #include #include namespace boost { namespace asio { /// Submits a completion token or function object for execution. /** * This function submits an object for execution using the object's associated * executor. The function object is queued for execution, and is never called * from the current thread prior to returning from defer(). * * The use of @c defer(), rather than @ref post(), indicates the caller's * preference that the executor defer the queueing of the function object. This * may allow the executor to optimise queueing for cases when the function * object represents a continuation of the current call context. * * This function has the following effects: * * @li Constructs a function object handler of type @c Handler, initialized * with handler(forward(token)). * * @li Constructs an object @c result of type async_result, * initializing the object as result(handler). * * @li Obtains the handler's associated executor object @c ex by performing * get_associated_executor(handler). * * @li Obtains the handler's associated allocator object @c alloc by performing * get_associated_allocator(handler). * * @li Performs ex.defer(std::move(handler), alloc). * * @li Returns result.get(). */ template BOOST_ASIO_INITFN_RESULT_TYPE(CompletionToken, void()) defer( BOOST_ASIO_MOVE_ARG(CompletionToken) token); /// Submits a completion token or function object for execution. /** * This function submits an object for execution using the specified executor. * The function object is queued for execution, and is never called from the * current thread prior to returning from defer(). * * The use of @c defer(), rather than @ref post(), indicates the caller's * preference that the executor defer the queueing of the function object. This * may allow the executor to optimise queueing for cases when the function * object represents a continuation of the current call context. * * This function has the following effects: * * @li Constructs a function object handler of type @c Handler, initialized * with handler(forward(token)). * * @li Constructs an object @c result of type async_result, * initializing the object as result(handler). * * @li Obtains the handler's associated executor object @c ex1 by performing * get_associated_executor(handler). * * @li Creates a work object @c w by performing make_work(ex1). * * @li Obtains the handler's associated allocator object @c alloc by performing * get_associated_allocator(handler). * * @li Constructs a function object @c f with a function call operator that * performs ex1.dispatch(std::move(handler), alloc) followed by * w.reset(). * * @li Performs Executor(ex).defer(std::move(f), alloc). * * @li Returns result.get(). */ template BOOST_ASIO_INITFN_RESULT_TYPE(CompletionToken, void()) defer( const Executor& ex, BOOST_ASIO_MOVE_ARG(CompletionToken) token, typename enable_if::value>::type* = 0); /// Submits a completion token or function object for execution. /** * @returns defer(ctx.get_executor(), forward(token)). */ template BOOST_ASIO_INITFN_RESULT_TYPE(CompletionToken, void()) defer( ExecutionContext& ctx, BOOST_ASIO_MOVE_ARG(CompletionToken) token, typename enable_if::value>::type* = 0); } // namespace asio } // namespace boost #include #include #endif // BOOST_ASIO_DEFER_HPP