October 2018
Intermediate to advanced
370 pages
9h 15m
English
Resource leaking can significantly impact the performance of an application, which is why it's important to release resources after using them. When we work with coroutines, we can just use the try {...} finally {...} block, even with long-term input/output operations.
The following example shows how we can use this block:
fun main(args: Array<String>) { launch { val fileReader = FileReader("path") try { delay(10000) fileReader.read() } finally { fileReader.close() } }}
Read now
Unlock full access