Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. import kotlinx.coroutines.delay
  2. import kotlinx.coroutines.launch
  3. import kotlinx.coroutines.runBlocking
  4. import kotlinx.coroutines.test.TestCoroutineContext
  5. import java.util.concurrent.TimeUnit
  6.  
  7. fun main() {
  8. val testCoroutineContext = TestCoroutineContext()
  9. runBlocking(testCoroutineContext) {
  10. // runRealWorldTime()
  11. launch { printIntegersWithDelay(10) }
  12. testCoroutineContext.advanceTimeBy(9, TimeUnit.MINUTES)
  13. println()
  14. delay(1000)
  15. testCoroutineContext.advanceTimeBy(9, TimeUnit.MINUTES)
  16. }
  17. }
  18.  
  19. suspend fun printIntegersWithDelay(count: Int) {
  20. repeat(count)
  21. {
  22. delay(100000)
  23. println ("${Thread.currentThread().id} $it")
  24. }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement