Complete the code to create a SupervisorJob instance.
val supervisor = [1]()The SupervisorJob() creates a job that allows child coroutines to fail independently.
Complete the code to launch a child coroutine with the supervisor job.
val scope = CoroutineScope(Dispatchers.Default + [1]()) scope.launch { println("Child coroutine running") }
Adding SupervisorJob() to the CoroutineScope allows child coroutines to fail independently.
Fix the error in the code to ensure child coroutines fail independently.
val supervisor = Job() val scope = CoroutineScope(Dispatchers.Default + [1]) scope.launch { throw Exception("Failure") }
Replacing Job() with SupervisorJob() allows child coroutines to fail independently without cancelling siblings.
Fill all three blanks to create a supervisor scope and launch two child coroutines where one fails independently.
val supervisor = [1]() val scope = CoroutineScope(Dispatchers.Default + supervisor) scope.[2] { println("Child 1 running") } scope.[3] { throw Exception("Child 2 failure") }
SupervisorJob() creates the supervisor job, and launch starts child coroutines.
Fill all three blanks to create a supervisor scope, launch a child coroutine that fails, and another that continues.
val supervisor = [1]() val scope = CoroutineScope(Dispatchers.Default + supervisor) scope.[2] { throw Exception("Failure in child") } scope.[3] { println("Independent child running") }
SupervisorJob() creates the supervisor job. Both children are started with launch, so one failing does not cancel the other.