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

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.
主站蜘蛛池模板: 阳原县| 灌南县| 丰都县| 榆树市| 泗洪县| 大化| 东兴市| 井冈山市| 罗源县| 额尔古纳市| 舟曲县| 渝北区| 寿阳县| 四会市| 土默特右旗| 隆安县| 鲜城| 禹城市| 永安市| 陆河县| 吉木乃县| 卫辉市| 彭阳县| 吉水县| 盐边县| 固安县| 北京市| 抚顺县| 磴口县| 景宁| 本溪市| 庆阳市| 蒲城县| 正蓝旗| 五寨县| 务川| 翁牛特旗| 阿克苏市| 涟水县| 乌恰县| 红河县|