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

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.
主站蜘蛛池模板: 天等县| 邻水| 维西| 永靖县| 盐亭县| 松潘县| 句容市| 仁怀市| 安丘市| 澄城县| 汪清县| 宝应县| 惠州市| 五家渠市| 巴塘县| 孝义市| 出国| 萝北县| 五大连池市| 昭觉县| 罗江县| 岳阳市| 平南县| 陆川县| 南丹县| 仁布县| 荔波县| 都江堰市| 达州市| 黄浦区| 汽车| 梅河口市| 东光县| 加查县| 金川县| 莲花县| 司法| 南康市| 志丹县| 正阳县| 斗六市|