How to Use C++20 Coroutines for Networking
summary
Shows a concrete recipe: prototype the chat in Lua prototype to learn suspension, then implement it in C++20 using co_await suspension semantics and Boost.Asio + GCC 11.2 + Boost 1.78. Compares three implementations (blocking ~49 lines, callback ~100 lines, coroutine ~50 lines) and a full chat example (~134 lines). Explains awaiters, promise types, coroutine_handle, co_spawn, suspend/resume mechanics, nonblocking stdin technique, and where library support (generators, executors) is heading.
AI-written summary · about
chapters (33)
- 0:00Start
- 1:14Poll
- 3:10Co-Routines the Fundamentals
- 7:43Benefit of Coroutines
- 8:58Multi-Threading
- 9:21Example Is an Echo Server
- 11:06Blocking Server
- 12:48Asynchronous Version
- 13:21Asynchronous Programming
- 15:19Accept Handler
- 17:27Co-Spawn
- 17:58Completion Token
- 21:37Co Routine Support in C plus plus 20
- 23:31Traits
- 24:46Tips for Learning
- 27:12Key References
- 32:16Chat Program
- 44:17Co-Routine Return Type
- 45:50Promise Type
- 46:20Customizing Car Weight
- 46:49Disable Car Weight on Certain Types
- 47:50Curvaturing Handles
- 48:44Example of a Generator
- 49:53Random Number Generator
- 50:44Co Routines Return Type
- 53:20Initial Suspend
- 57:31Networking Example of a Generator
- 57:47Packet Generator
- 1:00:39Design
- 1:01:46The Io Context
- 1:03:31Boost Timers
- 1:03:52Read the Keyboard
- 1:12:45Conclusion
related talks
47mHow to start using coroutines
01h 00mIntroduction to C++ Coroutines and gRPC and How to Write Coroutine Support Code
01h 04mNaked coroutines live (with networking)
01h 16mC++ Coroutines From Scratch
57mCoroutine Intuition in C++
01h 31mC++ Coroutines Demystified
01h 16mApplied C++20 Coroutines
01h 27mManage Asynchronous Control Flow With C++ Coroutines
