Created
February 19, 2020 00:55
-
-
Save jorgecasariego/bb6731107eb36315f48ad824691713a2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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() = 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