- 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.
推薦閱讀
- Mastering Ext JS(Second Edition)
- 零基礎(chǔ)學(xué)C++程序設(shè)計
- JavaScript:Functional Programming for JavaScript Developers
- Unity 2020 Mobile Game Development
- Scratch真好玩:教小孩學(xué)編程
- Visual C++應(yīng)用開發(fā)
- Learning Data Mining with R
- Visual Basic程序設(shè)計(第三版)
- 寫給青少年的人工智能(Python版·微課視頻版)
- 可視化H5頁面設(shè)計與制作:Mugeda標(biāo)準(zhǔn)教程
- Kotlin入門與實戰(zhàn)
- ServiceDesk Plus 8.x Essentials
- C++ Windows Programming
- Image Processing with ImageJ(Second Edition)
- Java EE 7 First Look