Hello! In io.ktor.network.selector.SelectorManager...
# ktor
p
Hello! In io.ktor.network.selector.SelectorManager there is 'dispatcher: CoroutineContext' as parameter. In example Dispathers.IO is passed. What if I pass Dispathers.DEFAULT? Does it mean that for choosing right dispatcher I need to know internals if it blocking or not? Why is it not hidden in internal implementation of SelectorManager?
d
I believe this is because
SelectorManager
is multiplatform (jvm+native) and that
<http://Dispatchers.IO|Dispatchers.IO>
does not exist yet for native. @e5l Am I right?
a
p
But why to expose it to public? Why not to resolve it in internal implementation?
a
Because it’s up to a user to decide what dispatcher to use.
p
So if I use Dispatcher.Default I will get blocking on it? Or if I use IO dispatcher and when internal implementation will be changed to fully non blocking I will continue to use inconvenient dispatcher. Leaky abstraction...
a
As I can see from the source code on native target the
Dispatcher.Default
is backed with a fixed-size thread-pool with the four threads.
p
Default dispatcher is for non blocking tasks. If in program will be created for example 4 SelectorManager with Default dispatcher then program has possibility to stuck, if less then not all threads will be working.