Skip to content

Instantly share code, notes, and snippets.

@GauravChaddha1996
Created January 30, 2021 17:28
Show Gist options
  • Save GauravChaddha1996/e19f0d08c2629497b0b5cae69703c41a to your computer and use it in GitHub Desktop.
Save GauravChaddha1996/e19f0d08c2629497b0b5cae69703c41a to your computer and use it in GitHub Desktop.
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