Kotlin 2 · Coroutines

Switch dispatcher

Run blocking or CPU-heavy work on a suitable dispatcher without blocking the caller.

val text = withContext(Dispatchers.IO) { File("data.txt").readText() }

Official Kotlin 2 documentation

More coroutines commands

All coroutines commands · Kotlin 2 cheatsheet

Was this page helpful?