]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/asio/co_spawn.hpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / boost / asio / co_spawn.hpp
1 //
2 // co_spawn.hpp
3 // ~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
6 //
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)
9 //
10
11 #ifndef BOOST_ASIO_CO_SPAWN_HPP
12 #define BOOST_ASIO_CO_SPAWN_HPP
13
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
15 # pragma once
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
17
18 #include <boost/asio/detail/config.hpp>
19
20 #if defined(BOOST_ASIO_HAS_CO_AWAIT) || defined(GENERATING_DOCUMENTATION)
21
22 #include <boost/asio/awaitable.hpp>
23 #include <boost/asio/execution_context.hpp>
24 #include <boost/asio/is_executor.hpp>
25
26 #include <boost/asio/detail/push_options.hpp>
27
28 namespace boost {
29 namespace asio {
30 namespace detail {
31
32 template <typename T>
33 struct awaitable_signature;
34
35 template <typename T, typename Executor>
36 struct awaitable_signature<awaitable<T, Executor>>
37 {
38 typedef void type(std::exception_ptr, T);
39 };
40
41 template <typename Executor>
42 struct awaitable_signature<awaitable<void, Executor>>
43 {
44 typedef void type(std::exception_ptr);
45 };
46
47 } // namespace detail
48
49 /// Spawn a new thread of execution.
50 /**
51 * The entry point function object @c f must have the signature:
52 *
53 * @code awaitable<void, E> f(); @endcode
54 *
55 * where @c E is convertible from @c Executor.
56 */
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),
66 typename enable_if<
67 is_executor<Executor>::value
68 >::type* = 0);
69
70 /// Spawn a new thread of execution.
71 /**
72 * The entry point function object @c f must have the signature:
73 *
74 * @code awaitable<void, E> f(); @endcode
75 *
76 * where @c E is convertible from @c ExecutionContext::executor_type.
77 */
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),
89 typename enable_if<
90 is_convertible<ExecutionContext&, execution_context&>::value
91 >::type* = 0);
92
93 } // namespace asio
94 } // namespace boost
95
96 #include <boost/asio/detail/pop_options.hpp>
97
98 #include <boost/asio/impl/co_spawn.hpp>
99
100 #endif // defined(BOOST_ASIO_HAS_CO_AWAIT) || defined(GENERATING_DOCUMENTATION)
101
102 #endif // BOOST_ASIO_CO_SPAWN_HPP