I <read today> that `kotlinx.coroutines.delay` on ...
# coroutines
j
I read today that
kotlinx.coroutines.delay
on Android uses
Handler.postDelayed
under the hood. That surprised me -- is it true? For Dispatcher.Main only, or all dispatchers?
z
Of the official
Dispatchers.*
dispatchers, it’s only for
Dispatchers.Main
, and only on Android. It’s also for any custom dispatchers derived from `Handler`s (thanks @Adam Powell for the correction). On jvm, delay uses the AWT/Swing event loop. The whole point of
Dispatchers.Main
is that it delegates to the current platform’s main thread event loop.
☝️ 1
m
I can only add related source code: https://github.com/Kotlin/kotlinx.coroutines/blob/master/ui/kotlinx-coroutines-android/src/HandlerDispatcher.kt#L55 and its documentation 🙂 I consider kotlin and coroutines implementation well-written and it usually clears all doubts one may have. I hope you’ll find it useful as well 🙂
j
Thanks!
a
It's for any dispatcher derived from a Handler, anyway.