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

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

主站蜘蛛池模板: 宁陵县| 苗栗县| 锡林浩特市| 武城县| 得荣县| 德江县| 宁明县| 开远市| 长葛市| 克什克腾旗| 铜陵市| 南昌市| 曲阳县| 固原市| 阳东县| 若羌县| 句容市| 莱芜市| 会理县| 桂林市| 方山县| 师宗县| 乌兰察布市| 西盟| 伊吾县| 永善县| 凤山县| 德惠市| 桃园市| 五指山市| 临颍县| 宽城| 咸丰县| 固原市| 西畴县| 阿拉善盟| 绥宁县| 新乐市| 白玉县| 罗平县| 天峨县|