Talking Async Ep1: Why C++20 is the Awesomest Language for Network Programming

Talking Async · 60K views · 2021 · 59:59

Open on YouTube

C, C++, Rust, Go & systems languagesSoftware architecture & designtalk

Why Stack Overflow recommends it

Stack Overflow users link it when asking or answering questions about Asio coroutines, awaitable operators, and cancellation, since it is the main walkthrough of these newer features from Asio's author.

Recommended by 2 people across 2 different months, 2022 to 2023.

What it is

The first episode of the Talking Async series, in which Chris Kohlhoff (author of Asio) and Klemens Morgenstern walk through new Asio features and C++20 coroutines with live coding. The example programs are published on GitHub.

What people said

Strong rec Bernd36 · 2022-08 · Stack Overflow · on “boost asio cancellation signal”

I think the most basic pattern is to use the (experimental) awaitable operators, like so: #include <boost/asio.hpp> #include <boost/asio/experimental/awaitable_operators.hpp> #include <iostream> #include <thread> namespace io = boost::asio; using namespace boost::asio::experimental::awaitable_operators; using namespace std::chrono_literals; io::awaitable<void> Cancelled(io::steady_timer& cancelTimer) { boost::system::error_code ec; co_await cancelTimer.async_wait(io::redirect_error(io::use_awaitable, ec)); } io::awaitable<void> AsyncOp(io::io_context& context) { io::steady_timer timer{ context, 100ms }; co_await timer.async_wait(io::use_awaitable); } io::awaitable<void> Run(io::io_context& c

Recommends sehe · 2023-06 · Stack Overflow · on “Recent technical documentation for boost asio”

@Nelfeal, this is great, thank you ! – Peter 1 hour ago [LINK] To wit, the Think-Async documentation [LINK] is identical to the Boost documentation [LINK] , but think-async.com used to have relevant blog posts. I think ironically, the blog posts sort-of dried up a little, but the Asio docs (mirrored in Boost) have grown tremendously over recent releases [LINK] , and I'm starting to consider them in-depth. This is in stark contrast with, say, 4 or 5 years ago, when I felt the best documentation of Asio principles and mechanisms were found in Beast (e.g. this article [LINK] used the be the only comprehensible documentation, whereas recent Asio documentation contains a wealth of different conce

Cites Koronis Neilos · 2022-03 · Stack Overflow · on “ASIO C++ coroutine cancellation”

To cancel a coroutine in asio use the new awaitable_operator '||'. The awaitable operator '||' allows to co_await for more than one coroutine until one of the coroutines is finished. For example: #include "boost/asio/experimental/awaitable_operators.hpp" #include <boost/asio.hpp> #include <boost/asio/deadline_timer.hpp> #include <boost/asio/detached.hpp> #include <boost/asio/system_timer.hpp> #include <boost/asio/this_coro.hpp> #include <chrono> #include <iostream> boost::asio::awaitable<void> printHelloEverySecond () { for (;;) { std::cout << "Hello" << std::endl; boost::asio::system_timer timer{ co_await boost::asio::this_coro::executor }; timer.expires_after (std::chrono::seconds{ 1 }); c

Cites Bernd36 · 2022-08 · Stack Overflow · on “Why do boost asio awaitable operators swallow exceptions?”

After watching this excellent talk Talking Async [this video] I am experimenting with boost asio awaitable operators for cancellation and timeouts with C++ 20 coroutines. While this works, I do not understand the error handling. The following program runs without an error message, whereas I would expect the output "for testing". #include <boost/asio.hpp> #include <boost/asio/experimental/awaitable_operators.hpp> #include <iostream> namespace io = boost::asio; using namespace boost::asio::experimental::awaitable_operators; using namespace std::chrono_literals; io::awaitable<void> Cancelled(io::steady_timer& cancelTimer) { boost::system::error_code ec; co_await cancelTimer.async_wait(io::redirect_e

Cites sehe · 2022-08 · Stack Overflow · on “Can I co_await an operation executed by one io_context in a coroutine executed by another in Asio?”

I ran out of time to get to the bottom of things and writing up a good, idiomatic counter-example. I kept seeing unexpected lifetime issues. I'm suspecting there's something going on under the hood with the new cancellation slots that I'm not fully aware of, so I was watching this [this video] and the next [LINK] .