Hacker News new | ask | show | jobs
by dxuh 634 days ago
Coroutines themselves are a really simple concept. But in practice they give you all the headaches async stuff generally gives you. And in C++ there is a ton of extra complication, especially because there is no support library. I wrote this in a tutorial a while ago:

> they are functions that can suspend themselves, meaning they stop themselves without returning, even in the middle of their body and then can later can be resumed, continuing execution at the point they suspended from earlier.

If you want to use coroutines in C++ specifically you can have a look at this tutorial, if you want: https://theshoemaker.de/posts/yet-another-cpp-coroutine-tuto... I don't know of anyone that read it, but I spent a lot of time on it.

It essentially tries to explain how to build a coroutine support library yourself, but if you don't care about that, skip it and just use libcoro or cppcoro. They have examples too. My little async io library has some examples as well if you want to get an idea.