Hello!, I have a question How to use <Dispatcher.I...
# coroutines
h
Hello!, I have a question How to use Dispatcher.IO? Kotlin Multiplatform doesn’t support Dispatchers.IO ?
kotlinx-coroutines = "1.8.1", kotlin = "2.0.0"
_commonMain_._dependencies_ *{*
implementation(_libs_._kotlinx_._coroutines_._core_)
}
_desktopMain_._dependencies_ *{*
implementation(_libs_._kotlinx_._coroutines_._swing_)
}
It worked for android & iOS projects, But I can't import in Android & iOS & Desktop & WasmJS projects [I tried upgrading to version 1.9.0-RC, and there was no change.]
c
IO only exists on the JVM (and Android). On JS, there are no threads, and no blocking IO, so it doesn't make sense. I don't know about iOS.
❤️ 1
Mistake?
h
@CLOVIS That's why, thank you! (Yes, that was a mistake.)
👍 1
r
You can do something like
expect val defaultAsyncDispatcher : CoroutineDispatcher
in jvmMain:
actual val defaultAsyncDispatcher : CoroutineDispatcher = <http://Dispatchers.IO|Dispatchers.IO>
everywhere else:
actual val defaultAsyncDispatcher : CoroutineDispatcher = Dispatchers.Default
(or Dispatchers.Main)
👍 1
d
You can use this extension property in common code
👍 1
Sorry I didn't notice you use wasm Dispatchers.IO is available only on JVM and native targets. There is no concurrency on js and wasm
👍 1
❤️ 1
141 Views