Skip to content

Instantly share code, notes, and snippets.

@GauravChaddha1996
Created January 30, 2021 17:28
Show Gist options
  • Save GauravChaddha1996/daebf63174a91e70d1b3394d013fdd65 to your computer and use it in GitHub Desktop.
Save GauravChaddha1996/daebf63174a91e70d1b3394d013fdd65 to your computer and use it in GitHub Desktop.
withTimeout(1000) {
repeat(100) { i ->
println("I'm sleeping $i ...")
delay(500L)
}
}
Output:
I'm sleeping 0 ...
I'm sleeping 1 ...
Exception in thread "main"
kotlinx.coroutines.TimeoutCancellationException: Timed out
waiting for 1000 ms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment