Last active
February 19, 2020 01:13
-
-
Save jorgecasariego/2231bc86558648fca4ea50f740fb984e 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
fun main() { | |
println("Start") | |
val activity = Activity() | |
activity.doLotOfThings() | |
Thread.sleep(2000) | |
activity.destroy() | |
println("Done") | |
} | |
class Activity : CoroutineScope by CoroutineScope(Dispatchers.Default) { | |
fun doLotOfThings() { | |
launch { | |
repeat(1_000) { | |
delay(400) | |
doThing() | |
} | |
} | |
} | |
private fun doThing() { | |
println("[${Thread.currentThread().name}] doing something...") | |
} | |
fun destroy() { | |
cancel() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment