Skip to content

Instantly share code, notes, and snippets.

@jorgecasariego
Created February 19, 2020 00:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jorgecasariego/bb6731107eb36315f48ad824691713a2 to your computer and use it in GitHub Desktop.
Save jorgecasariego/bb6731107eb36315f48ad824691713a2 to your computer and use it in GitHub Desktop.
fun main() = runBlocking {
log("Start")
hello()
log("Done")
}
private suspend fun hello() = coroutineScope {
launch {
// context of the parent, main runBlocking coroutine
println("[${Thread.currentThread().name}] from parent dispatcher")
}
launch(Dispatchers.Default) {
// will get dispatched to DefaultDispatcher
println("[${Thread.currentThread().name}] Dispatchers.Default")
}
launch(Dispatchers.IO) {
// will get dispatched to IO
println("[${Thread.currentThread().name}] Dispatchers.IO")
}
launch(Dispatchers.Unconfined) {
// not confined -- will work with main thread
println("[${Thread.currentThread().name}] Dispatchers.Unconfined")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment