C++ Coroutines Advanced: Converting std:future to asio:awaitable

34 xialeistudio 6 7/15/2025, 1:50:12 AM ddhigh.com ↗

Comments (6)

mgaunard · 51m ago
So the solution is to have a thread waiting on the future. Technically you'd need a thread per future, which is not exactly scalable. The article uses a pool which has its own problems.

The article even mentions an arguably better approach (check on a timer), but for some reasons claims it is worse.

Those integrations are not exactly good designs regardless; simply don't use std::future is the solution, and use non-blocking async mechanisms that can cooperate on the same thread instead. Standard C++ has one albeit somewhat overcomplicated, senders and receivers. Asio also works.

usrnm · 36m ago
Every time I read an article like this I thank the day when I switched from C++ to go. I know why C++ is like this, I understand all the hard work that went into evolving it over 40 years, but I simply refuse to deal with all this stuff anymore. I have better things to worry about in my life.
flakes · 47m ago
Seems prone to deadlocking- I would avoid making the thread-pool globally scoped, and instead provide it as arguments to the helper methods.
xialeistudio · 6h ago
In modern C++ development, coroutines have brought revolutionary changes to asynchronous programming. However, when using boost::asio or standalone asio, we often encounter scenarios where we need to convert traditional std::future<T> to asio::awaitable<T>. This article will detail an efficient, thread-safe conversion method.
userbinator · 1h ago
Did you just copy-paste the first paragraph of the article.
vlovich123 · 1h ago
It's literally his article.