spawn.hpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. //
  2. // Copyright (c) 2022 Klemens Morgenstern ([email protected])
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. #ifndef BOOST_COBALT_SPAWN_HPP
  8. #define BOOST_COBALT_SPAWN_HPP
  9. #include <boost/cobalt/detail/spawn.hpp>
  10. namespace boost::cobalt
  11. {
  12. template<with_get_executor Context, typename T, typename CompletionToken>
  13. auto spawn(Context & context,
  14. task<T> && t,
  15. CompletionToken&& token)
  16. {
  17. return asio::async_initiate<CompletionToken, void(std::exception_ptr, T)>(
  18. detail::async_initiate_spawn{}, token, std::move(t), context.get_executor());
  19. }
  20. template<std::convertible_to<executor> Executor, typename T, typename CompletionToken>
  21. auto spawn(Executor executor, task<T> && t,
  22. CompletionToken&& token BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(Executor))
  23. {
  24. return asio::async_initiate<CompletionToken, void(std::exception_ptr, T)>(
  25. detail::async_initiate_spawn{}, token, std::move(t), executor);
  26. }
  27. template<with_get_executor Context, typename CompletionToken>
  28. auto spawn(Context & context,
  29. task<void> && t,
  30. CompletionToken&& token)
  31. {
  32. return asio::async_initiate<CompletionToken, void(std::exception_ptr)>(
  33. detail::async_initiate_spawn{}, token, std::move(t), context.get_executor());
  34. }
  35. template<std::convertible_to<executor> Executor, typename CompletionToken>
  36. auto spawn(Executor executor, task<void> && t,
  37. CompletionToken&& token BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(Executor))
  38. {
  39. return asio::async_initiate<CompletionToken, void(std::exception_ptr)>(
  40. detail::async_initiate_spawn{}, token, std::move(t), executor);
  41. }
  42. }
  43. #endif //BOOST_COBALT_SPAWN_HPP