October 2019
Intermediate to advanced
434 pages
11h 54m
English
In our simple working example, GlobalScope is the coroutine scope for the launched coroutine:
fun main() { GlobalScope.launch { delay(500) println("Coroutines") } println("Hello") Thread.sleep(1000)}
A coroutine scope defines the lifetime of a coroutine. Coroutines within GlobalScope can exist for the lifetime of our application. This is similar to threads that will exist for the lifetime of the application if not cleaned up properly. The concept of coroutine scope allows us to restrict our coroutines so that we can specify contexts and life cycles within our application. This concept is known as structured concurrency.
We can create our own coroutine scope that ties into our applications' existing life cycles. For example, ...
Read now
Unlock full access