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

Suspending functions

Suspending functions are suspending computations in the shape of a function. A suspending function can be easily identified because of the modifier suspend. For example:

suspend fun greetAfter(name: String, delayMillis: Long) {
delay(delayMillis)
println("Hello, $name")
}

In the previous example, the execution of greetAfter() will be suspended when delay() is called – delay() is a suspending function itself, suspending the execution for a give duration. Once delay() has been completed, greetAfter() will resume its execution normally. And while greetAfter() is suspended, the thread of execution may be used to do other computations.

In Chapter 9, The Internals of Concurrency in Kotlin, we will talk about how this works behind the scenes.
主站蜘蛛池模板: 平原县| 徐州市| 砀山县| 行唐县| 靖江市| 南宁市| 五峰| 灌云县| 庆安县| 彝良县| 安徽省| 潞城市| 商城县| 牡丹江市| 沙田区| 永康市| 五莲县| 江西省| 巧家县| 个旧市| 靖西县| 上高县| 尤溪县| 嘉祥县| 金华市| 泊头市| 衢州市| 尉犁县| 和林格尔县| 洪湖市| 中西区| 阜新市| 龙山县| 石景山区| 绥滨县| 沙洋县| 修文县| 循化| 娄底市| 北碚区| 利川市|