Created
June 17, 2016 08:41
-
-
Save LMnet/16bb7349926709d242c8af9c5abe9fb4 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
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