Created
January 24, 2012 18:42
-
-
Save fpillet/1671801 to your computer and use it in GitHub Desktop.
Cancellable processing of iViewer CF.request calls
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
/* 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