When getting a job from launch, the job complete properly
fun testCoroutineScope() = runBlocking {
val scope = CoroutineScope(Dispatchers.Default)
val job = scope.launch {
delay(200)
println("Job done")
}
delay(500)
println(job.isCompleted)
}
Output:
Job done
true
But this is not the case when you combine your own job.
fun testCoroutineScope() = runBlocking {
var job = Job()
val scope = CoroutineScope(Dispatchers.Default + job)
scope.launch {
delay(200)
println("Job done")
}
delay(500)
println(job.isCompleted)
}
Output:
Job done
false
Looks like the job is never completed. Why is that?