https://kotlinlang.org logo
#ktor
Title
p

PHondogo

10/10/2022, 10:07 AM
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

Didier Villevalois

10/10/2022, 10:30 AM
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

Aleksei Tirman [JB]

10/10/2022, 10:33 AM
p

PHondogo

10/10/2022, 10:33 AM
But why to expose it to public? Why not to resolve it in internal implementation?
a

Aleksei Tirman [JB]

10/10/2022, 10:35 AM
Because it’s up to a user to decide what dispatcher to use.
p

PHondogo

10/10/2022, 10:43 AM
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

Aleksei Tirman [JB]

10/10/2022, 2:31 PM
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

PHondogo

10/10/2022, 2:38 PM
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.
10 Views