Created
April 4, 2020 15:08
lunch => function starts a new coroutine to execute the given lambda. The invoking code isn’t blocked for the completion of the coroutine.
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
import kotlinx.coroutines.launch | |
fun task1() { | |
println("Start task1 | Thread ${Thread.currentThread()}") | |
println("End task1 | Thread ${Thread.currentThread()}") | |
} | |
fun task2() { | |
println("Start task2 | Thread ${Thread.currentThread()}") | |
println("End task2 | Thread ${Thread.currentThread()}") | |
} | |
fun main() { | |
println("Start main") | |
runBlocking { | |
launch { task1() } | |
launch { task2() } | |
println("Called task1 and task2 from ${Thread.currentThread()}") | |
} | |
println("End main") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment