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