Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
val customDispatcher =
Executors.newSingleThreadExecutor().asCoroutineDispatcher()
launch(customDispatcher) {
println("Thread name: ${Thread.currentThread().name}")
withContext(Dispatchers.IO) {
delay(100)
println("Thread name: ${Thread.currentThread().name}")
}
println("Thread name: ${Thread.currentThread().name}")
println("Here to remind you that withContext
suspends the calling coroutine i.e. stops
execution of calling f()")
}
Output:
Thread name: pool-1-thread-1
Thread name: DefaultDispatcher-worker-1
Thread name: pool-1-thread-1
Here to remind you that withContext suspends the calling
coroutine i.e. stops execution of calling f()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment