Created
June 18, 2022 11:48
-
-
Save MasoudFallahpour/0cd8238916f65333cce3bba2d3acbfa0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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