Hi all! Is there any way to get `Dispatchers.main....
# javascript
j
Hi all! Is there any way to get `Dispatchers.main.immediate`behavior in JS? 🙂 The `immediate`dispatcher is not supported (yet) but would be nice to have
a
Just curious, what does the immediate dispatcher do?
j
if you are on the thread already, it will launch the work directly
instead of queuing it in the dispatcher
this is handy for UI work
but for bigger work it can block the thread you are working on
so it is a bit use with caution
a
thank you for your time
j
for example: If I load existing data to show in a view using flows, then with dispatcher.immediate it will push this directly to the view so it can display it in the 1st frame. With the normal dispatcher, it will post the work to the end of the queue, meaning the data might just be shown in the next frame (so the UI looks jumpy)
a
I think that explains why there is no immediate on js. You are always on the same main thread
j
well it is not just about being on the same thread, it is about scheduling work. Lets say I have a coroutine scope with a normal dispatcher:
Copy code
normalScope.launch { println(1) }
normalScope.launch { println(2) }
normalScope.launch { println(3) }
will result in:
Copy code
1
2
3
if we combine it with an immediate scope it could do this:
Copy code
normalScope.launch { println(1) }
normalScope.launch { println(2) }
immediateScope.launch { println(3) }
Which will result in:
Copy code
3
1
2
a
I see.