Skip to content

Instantly share code, notes, and snippets.

@jkassemi
Created December 31, 2013 06:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jkassemi/8193250 to your computer and use it in GitHub Desktop.
Save jkassemi/8193250 to your computer and use it in GitHub Desktop.
Run at most every X
loner = (fn, delay)->
lastRun = new Date()
timeout = null
runner = ->
args = arguments
clearTimeout(timeout) if timeout
wait = delay - (new Date() - lastRun)
wait = 0 if wait < 0
timeout = setTimeout =>
lastRun = new Date()
fn.apply(this, args)
timeout = null
, wait
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment