Created
March 18, 2020 09:33
-
-
Save erdemtopak/4e7690c05ed8213edfcdad06ff628532 to your computer and use it in GitHub Desktop.
Coroutine Execution For Humans
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
import kotlinx.coroutines.launch | |
import kotlinx.coroutines.runBlocking | |
object Main { | |
@JvmStatic | |
fun main(args: Array<String>) { | |
runBlocking { | |
val job = launch { | |
println("Coroutine start") | |
launch { | |
println("Child coroutine start") | |
launch { | |
println("Child-inner coroutine start") | |
println("Child-inner coroutine end") | |
} | |
println("Child coroutine end") | |
} | |
println("Coroutine end!") | |
} | |
println("Join") | |
println("Done") | |
} | |
} | |
} | |
/* | |
Output: | |
Join | |
Done | |
Coroutine start | |
Coroutine end! | |
Child coroutine start | |
Child coroutine end | |
Child-inner coroutine start | |
Child-inner coroutine end | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment