Now that the Promise
is officially specified, I am looking to convert the promise creation in the snippet below from $q.defer()
to using the
$q(function (resolve, reject) {})
constructor syntax. Can anyone help with this?
// To ensure only the most recent $http callback gets invoked,
// cancel any ongoing $http request
var canceller;
function getThing(id) {
if (canceller) canceller.resolve();
canceller = $q.defer();
return $http.get('/api/things/' + id, {
timeout: canceller.promise
});
}
(For reference, according to $http docs, timeout
is "… in milliseconds, or a promise that should abort the request when resolved.")