Coroutine Scenarios
Coroutine Scenarios
Generator
- 可以挂起返回很多值
- 当挂起的caller恢复运行时,使用value
- Lazy sequence
- 实现iterator/sentinel
// C++23实现该标准库 |
Task
类似函数调用的感觉
Caller
co_await
当task被创建task<T>::await_suspend()
存放caller-handle(in its promise)同时开始calleeThe stored handle is called the
continuation
task<T>::final_suspend()
resumes the continuation
Asynchronous I/O
await_suspend()
stores thecoroutine_handle<>
and registers a callback with the OSThe callback will put results in the
Awaiter
andresume()
the coroutineawait_resume()
provides the results to the coroutine
char data[1024]; |
Scheduler
- act as an
Awaitable
- 所有的actors 定期
co_await
struct Scheduler { |
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 LZY的Code生活!