Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save MasoudFallahpour/0cd8238916f65333cce3bba2d3acbfa0 to your computer and use it in GitHub Desktop.
Save MasoudFallahpour/0cd8238916f65333cce3bba2d3acbfa0 to your computer and use it in GitHub Desktop.
import kotlinx.coroutines.*
fun main() = runBlocking {
val job = launch {
println("Coroutine started.")
try {
delay(Long.MAX_VALUE)
} catch (ex: CancellationException) {
println("Coroutine cancelled.")
}
}
delay(1000)
println("Cancelling the coroutine...")
job.cancelAndJoin()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment