Created
December 20, 2019 14:26
-
-
Save qingwei91/3f7e3e683227d8a73ddb155acd43c20a to your computer and use it in GitHub Desktop.
Loop with termination logic built in
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
| def loop(stopsAfter: Duration) = { | |
| val start: Instant = Instant.now() | |
| while (true) { | |
| if (start.after(stopsAfter) < Instant.now()) { | |
| throw new NonTerminatingError() | |
| } else { | |
| // do your thing | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment