- 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.
推薦閱讀
- Clojure Programming Cookbook
- Git高手之路
- Ray分布式機器學習:利用Ray進行大模型的數據處理、訓練、推理和部署
- 零基礎學MQL:基于EA的自動化交易編程
- 小程序,巧運營:微信小程序運營招式大全
- FPGA Verilog開發實戰指南:基于Intel Cyclone IV(進階篇)
- 小程序,巧應用:微信小程序開發實戰(第2版)
- Microsoft 365 Certified Fundamentals MS-900 Exam Guide
- Red Hat Enterprise Linux Troubleshooting Guide
- 零基礎學Python編程(少兒趣味版)
- 自學Python:編程基礎、科學計算及數據分析(第2版)
- ASP.NET Web API Security Essentials
- Go語言入門經典
- WordPress Search Engine Optimization(Second Edition)
- Web前端開發最佳實踐