Multi-Try $.promise
This method wraps a provided callback that returns a jQuery promise (or jqXHR object) and allows that asynchronous functionality to fail and be retried without rejecting the returned promise.
multiTryPromise = (callback, numberOfTries, evaluate, options) ->
deferred = $.Deferred()
retry = =>
if deferred.state() is 'pending' and
numberOfTries and
(not evaluate? or evaluate arguments)
numberOfTries--
callback(options).then deferred.resolve, retry
else
deferred.rejectWith @, arguments
numberOfTries--
callback(options).then deferred.resolve, retry
deferred.promise()Written by Patrick Camacho
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Coffeescript
Authors
Did you know?
JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.
Security insights from Cside
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#