Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@magdamiu
Created April 11, 2020 10:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save magdamiu/d6cc48aecd70b56fa5f9956ae6701c3c to your computer and use it in GitHub Desktop.
Save magdamiu/d6cc48aecd70b56fa5f9956ae6701c3c to your computer and use it in GitHub Desktop.
Cancellation using withTimeout / withTimeoutOrNull
import kotlinx.coroutines.*
fun main() {
runBlocking {
withTimeout(1000L) {
repeat(50) { waitingTime ->
println("Job is waiting $waitingTime...")
delay(100L)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment