Vijayakumar M
06/21/2021, 2:34 PMval dispatcher = ScheduledThreadPoolExecutor(1).asCoroutineDispatcher()
val customScope = CoroutineScope(SupervisorJob() + dispatcher)
customScope.launch{
//This block works fine.
customScope.launch{
//This block is not executing
}
}
However it woks fine If I change the dispatcher in the inner block. But In my case, I need to have the same dispatcher in both launches.
Any help would be very much appreciated.Zach Klippenstein (he/him) [MOD]
06/21/2021, 3:06 PMZach Klippenstein (he/him) [MOD]
06/21/2021, 3:07 PMVijayakumar M
06/21/2021, 3:40 PMZach Klippenstein (he/him) [MOD]
06/21/2021, 3:45 PMVijayakumar M
06/21/2021, 4:03 PMbsimmons
06/21/2021, 4:10 PMlaunch for the inner one? (Instead of customScope.launch)Vijayakumar M
06/21/2021, 4:15 PMZach Klippenstein (he/him) [MOD]
06/21/2021, 4:27 PMVijayakumar M
06/21/2021, 4:35 PMval dispatcher = ScheduledThreadPoolExecutor(1).asCoroutineDispatcher()
val scope = CoroutineScope(SupervisorJob() + dispatcher)
fun cleanupStuff(){
scope.launch{
cleanupInternal().blockingAwait()
//other stuff
}
}
fun cleanupInternal(): Completable{
return Completable{
scope.launch{
//This block is not executing if called with in blocking manner like .blockingAwait() but works when I call with .subscribe()
}
}
}
When I change the cleanupInternal().blockingAwait() to “cleanupInternal().subscribe()” it works.
Why calling preference affects the implementation?bsimmons
06/21/2021, 4:36 PMZach Klippenstein (he/him) [MOD]
06/21/2021, 4:37 PMZach Klippenstein (he/him) [MOD]
06/21/2021, 4:39 PMblockingAwait from inside the scope.launch, which means you’re on the dedicated thread when the blockingAwait call blocks. blockingAwait will internally subscribe to your Completable, and trigger the scope.launch in cleanupInternal, but that coroutine can never launch because the thread that’s responsible for executing continuations (your dedicated thread) is blocked waiting for it to finish. Classic deadlock.Vijayakumar M
06/21/2021, 4:48 PMVijayakumar M
06/21/2021, 4:51 PM