🐦 Kotlin Intermediate

What is SupervisorJob in Kotlin coroutines?

Answer

In a regular coroutine scope with a standard Job, if any child coroutine fails, the exception cancels all other children and the parent. A SupervisorJob changes this behavior — each child coroutine is independent, so a failure in one child does not affect siblings. This is ideal for a ViewModel that makes multiple independent network requests in parallel — if one request fails, the others should continue. Android's viewModelScope uses a SupervisorJob internally. For finer control, use supervisorScope { } to create a temporary supervisor scope within your coroutine.