Coroutines Highlights - Scope
Júlio Siqueira
Senior Android Engineer | 8+ years | Mobile | Kotlin Software Developer | Java
1 - A CoroutineScope is a container for coroutines and coroutines context. It keeps track of any coroutine created within the scope, forming a hierarchy.
2 - launch and async builders are actually extensions of the CoroutineScope interface. So whenever we want to launch a coroutine, we need to start them in some scope
3 - Scope defines the? lifetime of the coroutine. When a scope is canceled, all coroutines launched within that scope are automatically canceled.?
For example, if we run the code below from an Android Activity and close the activity before the coroutine ends, will throw a CancellationException
4 - The coroutineScope reference can be used to cancel the coroutines manually or check if it is still active
References