Skip to content

Instantly share code, notes, and snippets.

@LMnet
Created June 17, 2016 08:41
Show Gist options
  • Save LMnet/16bb7349926709d242c8af9c5abe9fb4 to your computer and use it in GitHub Desktop.
Save LMnet/16bb7349926709d242c8af9c5abe9fb4 to your computer and use it in GitHub Desktop.
def debounce(wait: FiniteDuration)(f: ⇒ Unit): () ⇒ Unit = {
var lastStartTime = Long.MinValue
var finishTime = lastStartTime + wait.toMillis
() ⇒ {
val now = System.currentTimeMillis()
val ready = finishTime <= now
lastStartTime = now
finishTime = lastStartTime + wait.toMillis
if (ready) {
f
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment