Skip to content

Instantly share code, notes, and snippets.

@jorgecasariego
Last active February 19, 2020 01:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jorgecasariego/2231bc86558648fca4ea50f740fb984e to your computer and use it in GitHub Desktop.
Save jorgecasariego/2231bc86558648fca4ea50f740fb984e to your computer and use it in GitHub Desktop.
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