Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import kotlinx.coroutines.GlobalScope
- import kotlinx.coroutines.delay
- import kotlinx.coroutines.launch
- import kotlinx.coroutines.runBlocking
- fun main(args: Array<String>) {
- GlobalScope.launch { // launch new coroutine in background and continue
- delay(1000L)
- println("World!")
- }
- println("Hello,") // main thread continues here immediately
- runBlocking { // but this expression blocks the main thread
- delay(2000L) // ... while we delay for 2 seconds to keep JVM alive
- }
- }
Add Comment
Please, Sign In to add comment