elizarov
12/06/2017, 8:17 AMdave08
12/06/2017, 8:22 AMrunBlocking
or launch(Unconfined)
, is there a difference?yield
?elizarov
12/06/2017, 8:29 AMrunBlocking
confines the code to the invoker thread and blocks the invoker thread, while launch(Unconfined)
does not confine the code to any thread and does not block the invoker thread (invoker thread is busy only until coroutine suspends). Big difference. I’d suggest to (re)read the guide. This example from the guide explicitly shows this difference between thread-confined and unconfined, for example: https://github.com/Kotlin/kotlinx.coroutines/blob/master/coroutines-guide.md#unconfined-vs-confined-dispatcherdave08
12/06/2017, 9:03 AMUnconfined
is like no schedulers.. which in rx if we do a flatMap with a nested observable that uses a scheduler, the main observable (with no scheduler) that recieves the result will still be waiting on the thread it was run... whereas Unconfined might not do that if it ends up on another thread. So in conclusion, no schedulers in rx != Unconfined but rather to runBlocking surrounding it... or maybe only similar in some aspects...elizarov
12/06/2017, 9:06 AMinterval
operator without explicit scheduler. Will the invoker get blocked?dave08
12/06/2017, 9:08 AMobservable.flatMap { Observable.interval(...) }.subscribe()
?elizarov
12/06/2017, 9:10 AMfun main(args: Array<String>) {
Observable.interval(1, TimeUnit.SECONDS).subscribe {
println(Thread.currentThread().name)
}
println("Was I blocked or continue to run immediately?")
Thread.sleep(10_000)
}
dave08
12/06/2017, 9:17 AMelizarov
12/06/2017, 11:01 AM