Skip to content

Instantly share code, notes, and snippets.

@tdcolvin
Last active January 19, 2024 17:52
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 tdcolvin/fdc545d51d51ca75bd92e8c8b78bf9c8 to your computer and use it in GitHub Desktop.
Save tdcolvin/fdc545d51d51ca75bd92e8c8b78bf9c8 to your computer and use it in GitHub Desktop.
suspend fun countToAHundredBillion() {
var count = 0L
while(count < 100_000_000_000) {
count++
// Every 10,000 we yield to the coroutine
// dispatcher, allowing this loop to be
// cancelled if needed.
if (count % 10_000 == 0) {
yield()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment