5 // Copyright (c) 2003-2019 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_CO_SPAWN_HPP
12 #define BOOST_ASIO_CO_SPAWN_HPP
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18 #include <boost/asio/detail/config.hpp>
20 #if defined(BOOST_ASIO_HAS_CO_AWAIT) || defined(GENERATING_DOCUMENTATION)
22 #include <boost/asio/awaitable.hpp>
23 #include <boost/asio/execution_context.hpp>
24 #include <boost/asio/is_executor.hpp>
26 #include <boost/asio/detail/push_options.hpp>
33 struct awaitable_signature;
35 template <typename T, typename Executor>
36 struct awaitable_signature<awaitable<T, Executor>>
38 typedef void type(std::exception_ptr, T);
41 template <typename Executor>
42 struct awaitable_signature<awaitable<void, Executor>>
44 typedef void type(std::exception_ptr);
49 /// Spawn a new thread of execution.
51 * The entry point function object @c f must have the signature:
53 * @code awaitable<void, E> f(); @endcode
55 * where @c E is convertible from @c Executor.
57 template <typename Executor, typename F,
58 BOOST_ASIO_COMPLETION_TOKEN_FOR(typename detail::awaitable_signature<
59 typename result_of<F()>::type>::type) CompletionToken
60 BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(Executor)>
61 BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(CompletionToken,
62 typename detail::awaitable_signature<typename result_of<F()>::type>::type)
63 co_spawn(const Executor& ex, F&& f,
64 CompletionToken&& token
65 BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(Executor),
67 is_executor<Executor>::value
70 /// Spawn a new thread of execution.
72 * The entry point function object @c f must have the signature:
74 * @code awaitable<void, E> f(); @endcode
76 * where @c E is convertible from @c ExecutionContext::executor_type.
78 template <typename ExecutionContext, typename F,
79 BOOST_ASIO_COMPLETION_TOKEN_FOR(typename detail::awaitable_signature<
80 typename result_of<F()>::type>::type) CompletionToken
81 BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(
82 typename ExecutionContext::executor_type)>
83 BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(CompletionToken,
84 typename detail::awaitable_signature<typename result_of<F()>::type>::type)
85 co_spawn(ExecutionContext& ctx, F&& f,
86 CompletionToken&& token
87 BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(
88 typename ExecutionContext::executor_type),
90 is_convertible<ExecutionContext&, execution_context&>::value
96 #include <boost/asio/detail/pop_options.hpp>
98 #include <boost/asio/impl/co_spawn.hpp>
100 #endif // defined(BOOST_ASIO_HAS_CO_AWAIT) || defined(GENERATING_DOCUMENTATION)
102 #endif // BOOST_ASIO_CO_SPAWN_HPP