diff options
author | 2024-04-22 08:04:58 +1000 | |
---|---|---|
committer | 2024-04-22 08:04:58 +1000 | |
commit | 184292b730f4236bd4840e780fdad97ee060ec84 (patch) | |
tree | 67902161a465fe92aec78ca502de07092b8cde0f /3rdparty/asio/src/examples/cpp11/deferred/deferred_2.cpp | |
parent | 24154bc1f00790f344120b3a85175d6f616c5ad0 (diff) |
3rdparty/asio: Updated to 1.30.2
Diffstat (limited to '3rdparty/asio/src/examples/cpp11/deferred/deferred_2.cpp')
-rw-r--r-- | 3rdparty/asio/src/examples/cpp11/deferred/deferred_2.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/3rdparty/asio/src/examples/cpp11/deferred/deferred_2.cpp b/3rdparty/asio/src/examples/cpp11/deferred/deferred_2.cpp new file mode 100644 index 00000000000..07528282de5 --- /dev/null +++ b/3rdparty/asio/src/examples/cpp11/deferred/deferred_2.cpp @@ -0,0 +1,44 @@ +// +// deferred_2.cpp +// ~~~~~~~~~~~~~~ +// +// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +#include <asio.hpp> +#include <iostream> + +using asio::deferred; + +int main() +{ + asio::io_context ctx; + + asio::steady_timer timer(ctx); + timer.expires_after(std::chrono::seconds(1)); + + auto deferred_op = timer.async_wait( + deferred( + [&](std::error_code ec) + { + std::cout << "first timer wait finished: " << ec.message() << "\n"; + timer.expires_after(std::chrono::seconds(1)); + return timer.async_wait(deferred); + } + ) + ); + + std::move(deferred_op)( + [](std::error_code ec) + { + std::cout << "second timer wait finished: " << ec.message() << "\n"; + } + ); + + ctx.run(); + + return 0; +} |