Guest User

Untitled

a guest
Apr 2nd, 2019
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 0.54 KB | None | 0 0
  1. package main
  2.  
  3. import kotlinx.coroutines.GlobalScope
  4. import kotlinx.coroutines.delay
  5. import kotlinx.coroutines.launch
  6. import kotlinx.coroutines.runBlocking
  7.  
  8.  
  9. fun main(args: Array<String>) {
  10.     GlobalScope.launch { // launch new coroutine in background and continue
  11.         delay(1000L)
  12.         println("World!")
  13.     }
  14.     println("Hello,") // main thread continues here immediately
  15.     runBlocking {     // but this expression blocks the main thread
  16.         delay(2000L)  // ... while we delay for 2 seconds to keep JVM alive
  17.     }
  18. }
Add Comment
Please, Sign In to add comment