Kris Wong
06/09/2020, 8:19 PMrunBlocking(someContext), and within the block a call is made to a method that is calling launch using a scope that was created with the same context. however, it is not blocking. am I doing something wrong?octylFractal
06/09/2020, 8:20 PMstreetsofboston
06/09/2020, 8:23 PMlaunch is launched with a different scope, it will not participate in the structured concurrency of the calling scope.
It looks like sharing a CoroutineContext does not circumvent this...Kris Wong
06/09/2020, 8:23 PMrunBlocking(anObject.coroutineContext) {
anObject.doSomething()
}
and
fun doSomething() {
coroutineScope.launch {
...
}
}
finally
internal val coroutineContext = Executors.newSingleThreadExecutor().asCoroutineDispatcher()
private val coroutineScope = CoroutineScope(coroutineContext + SupervisorJob())Kris Wong
06/09/2020, 8:25 PMoctylFractal
06/09/2020, 8:26 PMdoSomething is not using a child job of runBlockingoctylFractal
06/09/2020, 8:27 PMrunBlocking lambda, and use that to launch the appropriate job, OR if you mean to make it separate, return the Job from doSomething() and join() on it in runBlockingKris Wong
06/09/2020, 8:27 PMKris Wong
06/09/2020, 8:28 PMKris Wong
06/09/2020, 8:30 PMKris Wong
06/09/2020, 8:30 PM