Created
January 30, 2021 17:28
-
-
Save GauravChaddha1996/e19f0d08c2629497b0b5cae69703c41a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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