C++ - Coroutines (Advanced)
Overview
Estimated time: 70–90 minutes
Implement coroutine machinery: promise types, custom awaiters, and safe lifetime patterns. Integrate cancellation.
Learning Objectives
- Define custom awaiters and promise types.
- Manage coroutine lifetimes and cancellation safely.
Prerequisites
Custom awaiter sketch
struct my_awaiter {
bool await_ready() const noexcept;
void await_suspend(std::coroutine_handle<>);
int await_resume();
};
Common Pitfalls
- Dangling handles and frames; ensure destroy() is called or use RAII wrappers.