Deciphering C++ Coroutines - A Diagrammatic Coroutine Cheat Sheet
summary
Step‑by‑step walkthrough of C++20 coroutine mechanics with copy‑paste skeletons: constructs a minimal coroutine and shows why the compiler requires a promise_type, how the return object is built, and how await_ready/await_suspend/await_resume control suspension. Demonstrates storing data in the promise, implementing generators (Fibonacci), toggling startup/shutdown with initial_suspend/final_suspend (suspend_always vs suspend_never), using coroutine_handle::resume/destroy, co_yield via promise::yield_value, and symmetric transfer by returning a handle from await_suspend.
AI-written summary · about
chapters (23)
- 0:00Start
- 2:39Overview
- 4:11Basics
- 6:24Asynchronous Computation
- 9:01Suspended Computation
- 9:28Compute the Fibonacci Sequence
- 13:17Function Signature
- 14:59Fibonacci Generator
- 18:17Futures and Promises
- 20:42Compile Errors
- 21:56Return Void Function
- 22:20An Unhandled Exception
- 22:41Functions Initial Suspend and Final Suspend
- 25:03Awaitable
- 27:29Weight Suspend
- 28:56Weight Resume
- 30:07Resume
- 30:24Destroy
- 31:20Convert from a Core Routine Handle to the Promise Object
- 36:33Resume Execution
- 51:19Hand Control Back to another Co-Routine
- 54:26Learning the Syntax
- 1:00:33Final Suspend
related talks
58mAn Introduction to C++ Coroutines
01h 05mCoroutines: C++ vs Rust
55mC++20 coroutines as an API principle
06mImplementing coroutines using C++17
04mLightning Talk: Implementing Coroutines Using C++17
47mC++ coroutines and Qt
01h 05mWhy use coroutines for asynchronous applications
57m[filtered] Asynchronous C++ Programming
