Created
September 12, 2024 09:57
-
-
Save trix0/ebb712aa2b9a0dbdedd8ddb3d88d9fd7 to your computer and use it in GitHub Desktop.
Kotlin Coroutines & Flows Masterclass, Coroutine basics Assignment #2
This file contains hidden or 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
GlobalScope.launch { | |
val cooBird = launch { | |
while (true){ | |
delay(1000) | |
println("Coo") | |
} | |
} | |
val cawBird = launch { | |
while (true){ | |
delay(2000) | |
println("Caw") | |
} | |
} | |
val chirpBird = launch { | |
while (true){ | |
delay(3000) | |
println("Chirp") | |
} | |
} | |
delay(10.seconds) | |
cooBird.cancel() | |
cawBird.cancel() | |
chirpBird.cancel() | |
println("Canceled") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment