Skip to content

Instantly share code, notes, and snippets.

@jorgecasariego
Created February 19, 2020 00:58
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/19bdbe67f91176a33ddbc948db561b57 to your computer and use it in GitHub Desktop.
Save jorgecasariego/19bdbe67f91176a33ddbc948db561b57 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")
}
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