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!
42
Upvotes
View all comments
Show parent comment
1
u/TheMania Feb 22 '26 edited Feb 22 '26
Most sane refactors are still fine though. If you have the lambda as a named variable, you can call and/or await it as many times as you like, and provided no coroutine outlives the lambda itself (eg by returning the
Task) it's all going to be fine.The only refactor that will give you trouble is the very code smelly one of keeping it as an immediately invoked lambda and saving only the task to a variable (your initial example). So don't do that.