Skip to content

Instantly share code, notes, and snippets.

@qingwei91
Created December 20, 2019 14:26
Show Gist options
  • Select an option

  • Save qingwei91/3f7e3e683227d8a73ddb155acd43c20a to your computer and use it in GitHub Desktop.

Select an option

Save qingwei91/3f7e3e683227d8a73ddb155acd43c20a to your computer and use it in GitHub Desktop.
Loop with termination logic built in
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