Introduction to coroutines
Nathan Baggs
C++20 introduced coroutines, a powerful new paradigm for structuring code. However the design and usage can be a bit obtuse when first approaching it.
High level ideas like "run code asynchronously" and "execute code whilst you wait for I/O" are often touted as advantages of coroutines, but:
- "If I'm waiting for I/O what code can get executed?"
- "How do I get resumed once I/O is done?"
- "How does this work with threads?"
Are often follow up questions, which lead to more confusion.
This workshop provides a practical approach to learning coroutines. We will go through a series of worked examples, including:
- My first coroutine
- Generators
- Async TCP server
- Coroutine based job scheduler
Each example provides an opportunity to write out, run and experiment with coroutine code. As well as to ask questions and understand the machinery behind coroutines.
Nathan Baggs
I've been using C++ professionally for nearly a decade. From C++98 to C++20 and across a variety of industries, I've worked on small to large scale C++ projects and had the opportunity to really see what the language can do.
I've always been passionate about teaching, working with others to expand their understanding and proficiency with the language.