Skip to content

Instantly share code, notes, and snippets.

@magdamiu
Last active April 4, 2020 14:58
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 magdamiu/67c89d107232e7e9dd12334a50e0e3a0 to your computer and use it in GitHub Desktop.
Save magdamiu/67c89d107232e7e9dd12334a50e0e3a0 to your computer and use it in GitHub Desktop.
runBlocking() => takes a lambda as an argument and executes that inside of a coroutine.
import kotlinx.coroutines.*
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 {
task1()
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