Skip to content

Instantly share code, notes, and snippets.

@mayojava
Created October 17, 2018 18:57
Show Gist options
  • Save mayojava/ce60c14799dbb9e098ce8cc5f07ea5d3 to your computer and use it in GitHub Desktop.
Save mayojava/ce60c14799dbb9e098ce8cc5f07ea5d3 to your computer and use it in GitHub Desktop.
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