| 1 | // Copyright (c) 2023 Klemens D. Morgenstern |
|---|---|
| 2 | // |
| 3 | // Distributed under the Boost Software License, Version 1.0. (See accompanying |
| 4 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
| 5 | |
| 6 | #include <boost/cobalt/detached.hpp> |
| 7 | |
| 8 | #include <boost/asio/steady_timer.hpp> |
| 9 | |
| 10 | using namespace boost; |
| 11 | |
| 12 | #include "test.hpp" |
| 13 | |
| 14 | BOOST_AUTO_TEST_SUITE(detached); |
| 15 | |
| 16 | cobalt::detached d(bool & done) |
| 17 | { |
| 18 | asio::steady_timer tim{co_await cobalt::this_coro::executor, std::chrono::milliseconds(10)}; |
| 19 | BOOST_CHECK_NO_THROW(co_await tim.async_wait(cobalt::use_op)); |
| 20 | done = true; |
| 21 | } |
| 22 | |
| 23 | BOOST_AUTO_TEST_CASE(detached) |
| 24 | { |
| 25 | asio::io_context ctx; |
| 26 | cobalt::this_thread::set_executor(ctx.get_executor()); |
| 27 | |
| 28 | bool done = false; |
| 29 | d(done); |
| 30 | |
| 31 | BOOST_CHECK(!done); |
| 32 | ctx.run(); |
| 33 | BOOST_CHECK(done); |
| 34 | } |
| 35 | |
| 36 | BOOST_AUTO_TEST_SUITE_END(); |
