Since Promise
is now officially spec-ed and all, how do I convert the $q.defer()
promise creation in the following snippet to use the $q(function (resolve, reject) {})
constructor syntax instead?
// Cancel any ongoing $http request so that only the most recent $http
// callback gets invoked
var canceller;
function getThing(id) {
if (canceller) canceller.resolve();
canceller = $q.defer();
return $http.get('/api/things/' + id, {
timeout: canceller.promise
});
}
(Fyi from $http docs: timeout
is "… in milliseconds, or promise that should abort the request when resolved.")