Skip to content

Instantly share code, notes, and snippets.

@GauravChaddha1996
Created January 30, 2021 17:25
Show Gist options
  • Save GauravChaddha1996/afe6f0fb7dfdcffc0e5ad8d48ee2770e to your computer and use it in GitHub Desktop.
Save GauravChaddha1996/afe6f0fb7dfdcffc0e5ad8d48ee2770e to your computer and use it in GitHub Desktop.
runBlocking {
val scope = CoroutineScope(Dispatchers.IO)
val j = scope.launch {
println("Inside parent job")
delay(50)
val p = launch {
println("Inside child job")
delay(500)
println("Ending of child job")
}
p.join()
println("Ending of parent job")
}
// Cancelling the parent after a 50ms delay
delay(50)
j.cancelAndJoin()
}
Output:
Inside parent job
Inside child job
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment