Skip to content

Instantly share code, notes, and snippets.

@sms-system
Created February 15, 2016 07:59
Show Gist options
  • Save sms-system/ed1b2395444980474273 to your computer and use it in GitHub Desktop.
Save sms-system/ed1b2395444980474273 to your computer and use it in GitHub Desktop.
wait = (condition, successCallback, time, timeoutCallback, frequency=250, loadingCallback) ->
time *= 1000 / frequency if time?
waiting = setInterval ->
if condition.call()
successCallback.call()
else if time? && --time <= 0
timeoutCallback?.call()
else
loadingCallback?.call()
return
clearInterval waiting
, frequency
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment