5 // Copyright (c) 2003-2020 Christopher M. Kohlhoff (chris at kohlhoff dot com)
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
11 #ifndef BOOST_ASIO_DISPATCH_HPP
12 #define BOOST_ASIO_DISPATCH_HPP
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18 #include <boost/asio/detail/config.hpp>
19 #include <boost/asio/async_result.hpp>
20 #include <boost/asio/detail/type_traits.hpp>
21 #include <boost/asio/execution_context.hpp>
22 #include <boost/asio/execution/executor.hpp>
23 #include <boost/asio/is_executor.hpp>
25 #include <boost/asio/detail/push_options.hpp>
30 /// Submits a completion token or function object for execution.
32 * This function submits an object for execution using the object's associated
33 * executor. The function object may be called from the current thread prior to
34 * returning from <tt>dispatch()</tt>. Otherwise, it is queued for execution.
36 * This function has the following effects:
38 * @li Constructs a function object handler of type @c Handler, initialized
39 * with <tt>handler(forward<CompletionToken>(token))</tt>.
41 * @li Constructs an object @c result of type <tt>async_result<Handler></tt>,
42 * initializing the object as <tt>result(handler)</tt>.
44 * @li Obtains the handler's associated executor object @c ex by performing
45 * <tt>get_associated_executor(handler)</tt>.
47 * @li Obtains the handler's associated allocator object @c alloc by performing
48 * <tt>get_associated_allocator(handler)</tt>.
50 * @li Performs <tt>ex.dispatch(std::move(handler), alloc)</tt>.
52 * @li Returns <tt>result.get()</tt>.
54 template <BOOST_ASIO_COMPLETION_TOKEN_FOR(void()) CompletionToken>
55 BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(CompletionToken, void()) dispatch(
56 BOOST_ASIO_MOVE_ARG(CompletionToken) token);
58 /// Submits a completion token or function object for execution.
60 * This function submits an object for execution using the specified executor.
61 * The function object may be called from the current thread prior to returning
62 * from <tt>dispatch()</tt>. Otherwise, it is queued for execution.
64 * This function has the following effects:
66 * @li Constructs a function object handler of type @c Handler, initialized
67 * with <tt>handler(forward<CompletionToken>(token))</tt>.
69 * @li Constructs an object @c result of type <tt>async_result<Handler></tt>,
70 * initializing the object as <tt>result(handler)</tt>.
72 * @li Obtains the handler's associated executor object @c ex1 by performing
73 * <tt>get_associated_executor(handler)</tt>.
75 * @li Creates a work object @c w by performing <tt>make_work(ex1)</tt>.
77 * @li Obtains the handler's associated allocator object @c alloc by performing
78 * <tt>get_associated_allocator(handler)</tt>.
80 * @li Constructs a function object @c f with a function call operator that
81 * performs <tt>ex1.dispatch(std::move(handler), alloc)</tt> followed by
84 * @li Performs <tt>Executor(ex).dispatch(std::move(f), alloc)</tt>.
86 * @li Returns <tt>result.get()</tt>.
88 template <typename Executor,
89 BOOST_ASIO_COMPLETION_TOKEN_FOR(void()) CompletionToken
90 BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(Executor)>
91 BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(CompletionToken, void()) dispatch(
93 BOOST_ASIO_MOVE_ARG(CompletionToken) token
94 BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(Executor),
96 execution::is_executor<Executor>::value || is_executor<Executor>::value
99 /// Submits a completion token or function object for execution.
101 * @returns <tt>dispatch(ctx.get_executor(),
102 * forward<CompletionToken>(token))</tt>.
104 template <typename ExecutionContext,
105 BOOST_ASIO_COMPLETION_TOKEN_FOR(void()) CompletionToken
106 BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(
107 typename ExecutionContext::executor_type)>
108 BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(CompletionToken, void()) dispatch(
109 ExecutionContext& ctx,
110 BOOST_ASIO_MOVE_ARG(CompletionToken) token
111 BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(
112 typename ExecutionContext::executor_type),
113 typename enable_if<is_convertible<
114 ExecutionContext&, execution_context&>::value>::type* = 0);
119 #include <boost/asio/detail/pop_options.hpp>
121 #include <boost/asio/impl/dispatch.hpp>
123 #endif // BOOST_ASIO_DISPATCH_HPP