-
-
Save rpl/305229 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// recovery | |
var httpReadOrRetry = function (url, timeout, times) { | |
return http.read(url).then(function (content) { | |
return content; | |
}, function (error) { | |
if (times == 0) | |
return error; | |
return delay(timeout).then(function () { | |
return httpReadOrRetry(url, timeout, times - 1); | |
}); | |
}); | |
} | |
// promise-based wrapper for setTimeout | |
var delay = function (timeout) { | |
var deferred = new Deferred(); | |
setTimeout(function () { | |
deferred.resolve(); | |
}, timeout); | |
return deferred.promise; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment