r/cpp • u/rhidian-12_ Coroutines4Life • Feb 21 '26
Implementing your own asynchronous runtime for C++ coroutines
Hi all! Last time I wrote a blog post about writing your own C++ coroutines. Now, I wanted to highlight how to write your own C++ asynchronous runtime for your coroutines.
https://rhidian-server.com/how-to-create-your-own-asynchronous-runtime-in-c/
Thanks for reading, and let me know if you have any comments!
44
Upvotes
View all comments
Show parent comment
1
u/TheMania Feb 22 '26
Well it's the way I write most of mine these days, it has the advantage that you can spawn multiple via the same task factory, perhaps parameterised differently. I'll write a few lambdas at the top of the scope, and then the actual body referring to the named functions.
I'll typically give them meaningful names, of course.
To me that looks like a dangerous refactor, as there's no
this autoin an IIFE, but agreed. It's a pain that convention has to be relied on to use them safely. Whether that's to use named lambdas, this auto, to await in the same expression, or to not use stateful lambdas at all.