官术网_书友最值得收藏!

  • 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 8Concurrency and Multithreading.

主站蜘蛛池模板: 兴义市| 林甸县| 彭山县| 胶南市| 四川省| 通山县| 嘉定区| 吉安市| 嘉义县| 孝昌县| 柳林县| 齐河县| 台北县| 思茅市| 松溪县| 察雅县| 房产| 绩溪县| 黄平县| 承德市| 辽源市| 江安县| 百色市| 英德市| 临潭县| 离岛区| 平罗县| 拉萨市| 凤翔县| 峨边| 和顺县| 陵川县| 滦南县| 永寿县| 弋阳县| 卢湾区| 静安区| 大理市| 靖西县| 金秀| 屏南县|