- 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.
推薦閱讀
- Learning Python Web Penetration Testing
- 深度實踐OpenStack:基于Python的OpenStack組件開發
- 自己動手寫搜索引擎
- Hands-On Data Structures and Algorithms with JavaScript
- Vue.js快速入門與深入實戰
- 深入淺出Spring Boot 2.x
- R語言數據可視化實戰
- Scala Reactive Programming
- Natural Language Processing with Java and LingPipe Cookbook
- Python機器學習算法與應用
- 多媒體技術及應用
- Drupal 8 Development Cookbook(Second Edition)
- Flink核心技術:源碼剖析與特性開發
- Socket.IO Cookbook
- TensorFlow程序設計