Created
October 17, 2018 18:57
-
-
Save mayojava/ce60c14799dbb9e098ce8cc5f07ea5d3 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
fun main (args: Array<String>) = runBlocking { | |
println("current thread: ${Thread.currentThread().name}") | |
//switch to default Dispatcher | |
val result = withContext(Dispatchers.Default) { | |
delay(500) | |
println("Thread: ${Thread.currentThread().name}") | |
100 | |
} | |
println("result: $result") | |
println("back on: ${Thread.currentThread().name}") | |
} | |
//prints the following | |
current thread: main | |
Thread: DefaultDispatcher-worker-1 | |
result: 100 | |
back on: main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment