- Learning Concurrency in Kotlin
- Miguel Angel Castiblanco Torres
- 113字
- 2021-08-05 10:46:45
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.
推薦閱讀
- iOS Game Programming Cookbook
- Android開發精要
- Java面向對象思想與程序設計
- Learn Programming in Python with Cody Jackson
- PHP 編程從入門到實踐
- 深入淺出Serverless:技術原理與應用實踐
- 小學生C++創意編程(視頻教學版)
- PhoneGap:Beginner's Guide(Third Edition)
- Unreal Engine 4 Shaders and Effects Cookbook
- INSTANT Passbook App Development for iOS How-to
- Keras深度學習實戰
- Learning Docker Networking
- 寫給程序員的Python教程
- SQL Server 2016 從入門到實戰(視頻教學版)
- 實戰Java高并發程序設計(第2版)