Allow Dispatchers.Unconfined
to use the event loops as time sources
#4185
Labels
Dispatchers.Unconfined
to use the event loops as time sources
#4185
What do we have now?
currently outputs
DefaultExecutor
is the thread backing the whole kotlinx.coroutines framework, and its availability is important fordelay
s to work correctly. We shouldn't give it arbitrary tasks to execute if we can avoid it.What should be instead?
Before the
delay
, theUnconfined
dispatcher uses the event loop created byrunBlocking
to execute its tasks. That event loop is also adelay
, sodelay(100)
could execute inrunBlocking
as well, which would mean the unconfined task would be resumed in that same event loop, not bothering theDefaultExecutor
.Why?
Improved availability of
DefaultExecutor
could decrease the latency of resumption of tasks afterdelay
in some scenarios.Why not?
We haven't actually seen this being a problem in the wild:
Dispatchers.Unconfined
rarely needs to calldelay
, just by the nature of the tasks typically executing in it. Also, in the cases where it does happen, this could be a breaking change.The text was updated successfully, but these errors were encountered: