Sushobh
11/01/2022, 2:18 AMstreetsofboston
11/01/2022, 3:24 AMCorountineScope(coroutineContext + Job())
Sushobh
11/01/2022, 3:49 AMCorountineScope(coroutineContext + Job())"
Tried this exactly, but runBlocking still waits for coroutines launched in this scope. This was the first thing that I tried doing actually,gildor
11/01/2022, 7:48 AMgildor
11/01/2022, 7:48 AMMy question is what parameter of coroutine context does runBlocking use to decide if it wants to wait for a launched coroutine.As Anton staid, any scope/job/context created from runBlocking scope as parent will be linked to runBlocking
Sushobh
11/01/2022, 8:18 AM@Test
fun coroutineTest19() = runBlocking {
val newScope = CoroutineScope(coroutineContext + Job())
newScope.launch(<http://Dispatchers.IO|Dispatchers.IO>) {
var count = 0
while(true){
Thread.sleep(1000)
println("Hello ${count++}")
}
}
Unit
}
In this case runBlocking does wait.
@Test
fun coroutineTest19() = runBlocking {
val newScope = CoroutineScope(coroutineContext)
newScope.launch(<http://Dispatchers.IO|Dispatchers.IO>) {
var count = 0
while(true){
Thread.sleep(1000)
println("Hello ${count++}")
}
}
Unit
}
I had somehow gotten confused. Thanks for your helpgildor
11/01/2022, 1:42 PMSushobh
11/01/2022, 2:02 PMgildor
11/01/2022, 2:13 PM