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

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.
主站蜘蛛池模板: 方城县| 丹阳市| 辽宁省| 北宁市| 留坝县| 开封市| 浮山县| 乌审旗| 正阳县| 海南省| 修水县| 日土县| 曲水县| 自治县| 巴林左旗| 卢湾区| 辽源市| 明水县| 平定县| 龙川县| 诸城市| 沛县| 普宁市| 新干县| 家居| 镇安县| 龙州县| 西林县| 林州市| 景谷| 高州市| 福州市| 白银市| 宿州市| 铜陵市| 航空| 桂林市| 泰州市| 蒙山县| 柯坪县| 双辽市|