Image from: https://www.smeup.com/eventi/kotlin-conference-milan-2019/

Kotlin Coroutine Job Lifecycle

How manage the Lifecycle of a Coroutine Job

The CoroutineScope and the Inheritance

  • Coroutine Dispatcher: it works like a Thread Pool, by default Dispatchers.Default
  • Coroutine Name: the name of coroutine (used for debugging)
  • Parent Job: the parent Job of children jobs, by default is null
  • Coroutine Exception Handler: the callback to handle coroutine exception inside the job
CoroutineScope parameters
Example of CoroutineScope

Coroutine Parent Job Behavior and Cancellation

Cancelation of first Job
Cancelation of parent Job
Android ViewModel example
Image from: https://giphy.com/gifs/siliconvalleyhbo-hbo-silicon-valley-l4FGHHVuEqMi0RBq8

Coroutines Job States

Coroutine Job States

Thanks for reading

--

--

Senior Android Engineer @ Moneyfarm

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store