On Android we have the `<http://Dispatchers.IO|Dis...
# multiplatform
c
On Android we have the
<http://Dispatchers.IO|Dispatchers.IO>
available, but that's not the case in KMM. What's the best way to replace it? I already have a
expected
actual
with a
Dispatcher.SharedIO
which just points to
<http://Dispatchers.IO|Dispatchers.IO>
on Android, but what's the best solution on iOS?
👀 3
s
s
@shahroz Looking through Kotlin’s coroutines source code, isn’t your iOS dispatcher equivalent to Kotlin’s
Dispatchers.Main
implementation anyway? https://github.com/Kotlin/kotlinx.coroutines/blob/master/kotlinx-coroutines-core/nativeDarwin/src/Dispatchers.kt#L32-L43 (and https://github.com/Kotlin/kotlinx.coroutines/blob/master/kotlinx-coroutines-core/native/src/Dispatchers.kt)
c
Dispatchers.Main
seems to use the main dispatch queue, that would block the main thread I assume? (not an iOS dev)
But I think the
DarwinGlobalQueueDispatcher
which is mapped to
Dispatchers.Default
does pretty much the same
s
@Christian Würthenr Yes
Dispatchers.Main
would block the main thread afaik
c
I also assumed that I can replace
<http://Dispatchers.IO|Dispatchers.IO>
with
Dispatchers.Default
in KMM, but that lead to the app being dead locked on devices with low CPU core counts as on Android
Dispatchers.Default
is limited to one thread per core. Looking at the iOS implementation now, that seems not to be the case on iOS
So I guess my approach is fine...
Copy code
expect Dispatchers.SharedIO: CoroutineDispatcher
iOS is then
Copy code
actual Dispatchers.SharedIO = Dispatchers.Default
and Android
Copy code
actual Dispatchers.SharedIO = <http://Dispatchers.IO|Dispatchers.IO>
s
There is a similar issue, for me
Dispatchers.Default
limited thread count seemed to be a problem. But maybe,
newFixedThreadPoolContext
can fix this
c
But it should not be fixed, right? Because the IO dispatcher is ment to be blocked for any IO. It should be allowed to create new threads as needed as the others will be "busy" waiting for IO
s
Yup it won't fix it, but this is the best alternate we have for now
c
Ok, great! Thanks for the input!!
🙂