Skip to content

Instantly share code, notes, and snippets.

@fpillet
Created January 24, 2012 18:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fpillet/1671801 to your computer and use it in GitHub Desktop.
Save fpillet/1671801 to your computer and use it in GitHub Desktop.
Cancellable processing of iViewer CF.request calls
/* Use RequestQueue.request() instead of CF.request()
* At any point, to cancel all pending callbacks, call RequestQueue.clear()
*
*/
var RequestQueue = (function(){
var self = {
q: [],
next: 0
};
self.request = function(url, method, headers, body, callbackFunction) {
var reqid = self.next++;
self.q[reqid] = true;
CF.request(url, method, headers, body, function(status, resHeader, resBody) {
if (self.q[reqid] !== undefined) {
callbackFunction.apply(null, [status, resHeader, resBody]);
delete self.q[reqid]
}
});
};
// call this at any point to wipe the queue clean
self.clear = function() {
self.q = [];
};
return self;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment