Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

89 lines
2.3KB

  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. #ifndef ASIO_CO_SPAWN_HPP
  11. #define ASIO_CO_SPAWN_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include "asio/detail/config.hpp"
  16. #if defined(ASIO_HAS_CO_AWAIT) || defined(GENERATING_DOCUMENTATION)
  17. #include "asio/awaitable.hpp"
  18. #include "asio/execution_context.hpp"
  19. #include "asio/is_executor.hpp"
  20. #include "asio/detail/push_options.hpp"
  21. namespace asio {
  22. namespace detail {
  23. template <typename T>
  24. struct awaitable_signature;
  25. template <typename T, typename Executor>
  26. struct awaitable_signature<awaitable<T, Executor>>
  27. {
  28. typedef void type(std::exception_ptr, T);
  29. };
  30. template <typename Executor>
  31. struct awaitable_signature<awaitable<void, Executor>>
  32. {
  33. typedef void type(std::exception_ptr);
  34. };
  35. } // namespace detail
  36. /// Spawn a new thread of execution.
  37. /**
  38. * The entry point function object @c f must have the signature:
  39. *
  40. * @code awaitable<void, E> f(); @endcode
  41. *
  42. * where @c E is convertible from @c Executor.
  43. */
  44. template <typename Executor, typename F, typename CompletionToken>
  45. ASIO_INITFN_RESULT_TYPE(CompletionToken,
  46. typename detail::awaitable_signature<typename result_of<F()>::type>::type)
  47. co_spawn(const Executor& ex, F&& f, CompletionToken&& token,
  48. typename enable_if<
  49. is_executor<Executor>::value
  50. >::type* = 0);
  51. /// Spawn a new thread of execution.
  52. /**
  53. * The entry point function object @c f must have the signature:
  54. *
  55. * @code awaitable<void, E> f(); @endcode
  56. *
  57. * where @c E is convertible from @c ExecutionContext::executor_type.
  58. */
  59. template <typename ExecutionContext, typename F, typename CompletionToken>
  60. ASIO_INITFN_RESULT_TYPE(CompletionToken,
  61. typename detail::awaitable_signature<typename result_of<F()>::type>::type)
  62. co_spawn(ExecutionContext& ctx, F&& f, CompletionToken&& token,
  63. typename enable_if<
  64. is_convertible<ExecutionContext&, execution_context&>::value
  65. >::type* = 0);
  66. } // namespace asio
  67. #include "asio/detail/pop_options.hpp"
  68. #include "asio/impl/co_spawn.hpp"
  69. #endif // defined(ASIO_HAS_CO_AWAIT) || defined(GENERATING_DOCUMENTATION)
  70. #endif // ASIO_CO_SPAWN_HPP