Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Cancellable deferreds

View cancellable-deferreds.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
var deferredsByPromise = new WeakMap();
 
recordRetriever.retrieveAsync = function (query) {
var deferred = Q.defer();
 
server.doPagedRetrieveWithCallback(query, 0, function (err, result) {
// wire up deferred.resolve and deferred.reject.
// recurse appropriately, increasing pagination,
// UNLESS deferred.isCancelled.
});
 
deferredsByPromise.set(deferred.promise, deferred);
return deferred.promise;
};
 
recordRetriever.cancel = function (promise) {
var deferred = deferredsByPromise.get(promise);
deferred.cancel();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.