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

  • 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.

主站蜘蛛池模板: 永仁县| 阿拉善左旗| 明水县| 曲阳县| 甘谷县| 古田县| 青海省| 通榆县| 游戏| 临沭县| 开鲁县| 行唐县| 新泰市| 云南省| 扎兰屯市| 彝良县| 高要市| 阿拉尔市| 克什克腾旗| 中牟县| 湘阴县| 新建县| 松阳县| 邓州市| 京山县| 普宁市| 从化市| 贺州市| 思茅市| 肥东县| 沙湾县| 吉首市| 荆门市| 枞阳县| 洛扎县| 秦安县| 扎赉特旗| 聂拉木县| 嵊州市| 丰原市| 文昌市|