io Dispatcher
The dispatcher for blocking calls (file reads, sockets, JDBC) from common code.
Dispatchers.IO exists only on some targets. Use ioDispatcher in commonMain wherever you would write Dispatchers.IO on the JVM.
Example
val bytes = withContext(ioDispatcher) { readFileBlocking(path) }Content copied to clipboard
Platform differences
| Target | ioDispatcher is |
|---|---|
| JVM, Android, iOS, macOS | Dispatchers.IO, a thread pool that grows on demand |
| JS, Wasm | the dispatcher from installIoDispatcher, else Dispatchers.Default |
Watch out
Browsers and Node have no thread pool. Without installIoDispatcher, JS and Wasm fall back to Dispatchers.Default, which is the main thread. The first read then logs one console warning.
Every read returns the currently installed dispatcher. A value that you stored before installIoDispatcher keeps the old dispatcher.