Skip to content

Instantly share code, notes, and snippets.

@utybo
Created May 8, 2021 15:39
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Illustration of event loop in runBlocking
import kotlinx.coroutines.*
fun printCurrentThread(prefix: Int) {
println("[$prefix] I'm in: " + Thread.currentThread().name)
}
fun main() {
printCurrentThread(1)
runBlocking {
printCurrentThread(2)
launch {
printCurrentThread(3)
}
printCurrentThread(4)
delay(100) // Just to suspend
printCurrentThread(5)
}
}
/*
Output:
[1] I'm in: main
[2] I'm in: main @coroutine#1
[4] I'm in: main @coroutine#1
[3] I'm in: main @coroutine#2
[5] I'm in: main @coroutine#1
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment