Last active
January 19, 2024 17:52
-
-
Save tdcolvin/fdc545d51d51ca75bd92e8c8b78bf9c8 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
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