How to implement Dispatchers.Main and bind the mai...
# coroutines
a
How to implement Dispatchers.Main and bind the main thread into it?
unfortunately I don't think you can bind to
Dispatchers.Main
because it's internal, but this is close
a
Ohh nice. Thanks for the help 😊
@octylFractal Btw what are immediate dispatchers, never heard of em.
o
it's part of the
Dispatcher.Main
setup, allowing you to dispatch on the same thread if you're already on the main thread. essentially this pseudocode:
if (mainThread) runnable() else dispatch(runnable)
a
ohh
o
that's the effect if you do
scope.launch(mainDispatcher.immediate) { ... }
a
what if when launching without immediate when currently on main?
o
it acts just like a normal dispatcher then
a
How about this approach? This uses the backing event-loop to do the same, https://stackoverflow.com/a/54195483/11377112
o
it's okay, you can't get the same
immediate
benefit though
a
ohh, now i understood. It'd be better to use something like your implementation. Thanks again for your time 😉😊😁