Last active
August 29, 2015 13:56
-
-
Save yeliu84/8978855 to your computer and use it in GitHub Desktop.
HTTP request with timer by promise
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
// http://www.slideshare.net/domenicdenicola/the-promised-land-in-angular?utm_source=ng-newsletter&utm_campaign=356fbe22fa-AngularJS_Newsletter_2_11_142_10_2014&utm_medium=email&utm_term=0_fa61364f13-356fbe22fa-90279177 | |
function timer(promise, ms) { | |
var deferred = $q.defer(); | |
promise.then(deferred.resolve, deferred.reject); | |
setTimeout(function() { | |
deferred.reject(new Error('oops, timed out!')); | |
}, ms); | |
return deferred.promise; | |
} | |
function httpGetWithTimer(url, ms) { | |
return timer(http.get(url), ms); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment