Casey Brooks
12/20/2019, 6:57 PMrunBlocking
, so I tried to set up a polling solution with .launch { }
and usleep()
, but it doesn’t seem like the launched block ever executes.println("before launch")
PlatformApiUtils.mainCoroutineScope.launch {
println("before block")
block()
println("after block")
isDoneAtomic.lazySet(true)
}
println("after launch")
println("before polling")
while(true) {
... poll for completion of '.launch { }'
}
Dispatcher
class UI : CoroutineDispatcher() {
override fun dispatch(context: CoroutineContext, block: Runnable) {
val queue = dispatch_get_main_queue()
dispatch_async(queue) {
block.run()
}
}
}
Output
before launch
after launch
before polling // I'd expect logging from inside the block after this line
polling timeout reached