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

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.

主站蜘蛛池模板: 东辽县| 腾冲县| 清水河县| 佛教| 长兴县| 尼木县| 鲜城| 无极县| 奈曼旗| 海盐县| 台前县| 临清市| 清镇市| 大竹县| 新和县| 鄂托克前旗| 股票| 平安县| 黑水县| 广元市| 竹溪县| 铁岭县| 绥中县| 易门县| 乌拉特后旗| 吐鲁番市| 湟中县| 南昌县| 阿拉尔市| 晋江市| 合作市| 洪湖市| 临洮县| 萝北县| 仪陇县| 苏州市| 泸西县| 肇州县| 罗山县| 曲水县| 山西省|