- Expert C++
- Vardan Grigoryan Shunguang Wu
- 118字
- 2021-06-24 16:33:52
Coroutines
Coroutines are special functions able to stop at any defined point of execution and resume later. Coroutines extend the language with the following new keywords:
- co_await suspends the execution of the coroutine.
- co_yield suspends the execution of the coroutine while also returning a value.
- co_return is similar to the regular return keyword; it finishes the coroutine and returns a value. Take a look at the following classic example:
generator<int> step_by_step(int n = 0) {
while (true) {
co_yield n++;
}
}
A coroutine is associated with a promise object. The promise object stores and alerts the state of the coroutine. We will dive deeper into coroutines in Chapter 8, Concurrency and Multithreading.
推薦閱讀
- Vue 3移動(dòng)Web開發(fā)與性能調(diào)優(yōu)實(shí)戰(zhàn)
- Learning Neo4j
- JavaScript百煉成仙
- 程序設(shè)計(jì)與實(shí)踐(VB.NET)
- 大學(xué)計(jì)算機(jī)基礎(chǔ)實(shí)驗(yàn)教程
- Learning OpenStack Networking(Neutron)
- Spring快速入門
- ServiceNow:Building Powerful Workflows
- C++編程兵書
- Solutions Architect's Handbook
- Managing Microsoft Hybrid Clouds
- 大學(xué)計(jì)算機(jī)基礎(chǔ)實(shí)訓(xùn)教程
- 面向?qū)ο蟪绦蛟O(shè)計(jì)及C++(第3版)
- Learning D3.js 5 Mapping(Second Edition)
- 現(xiàn)代C++語(yǔ)言核心特性解析