NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
A simple queue for GM_xmlhttpRequests or other async functions
new RequestQueue([maxParallel[, maxTotal]])
RequestQueue.prototype.add(req[, fun[, thisArg]])
Schedule a request
Results in a call like this: thisArg.fun(req)
RequestQueue.prototype.abortRunning()
For all scheduled requests that are currently running: result = thisArg.fun(req)
this will call result.abort()
For GM_xmlhttpRequest this will subsequently fire an onabort event
RequestQueue.prototype.abortPending()
Clear the list of pending requests i.e. requests that were not sent yet.
RequestQueue.prototype.abort()
Abort both running and pending requests
Example:
var rq = new RequestQueue(1); // 1 -> Allow no parallel requests
rq.add({
method: "GET",
url: "http://www.example.org/page1",
onload: function (response){
console.log("onload 1");
}
});
rq.add({
method: "GET",
url: "http://www.example.org/page2",
onload: function (response){
console.log("onload 2");
}
});
The request to page 1 will be sent immediately.
The request to page 2 will be sent after the the first request has finished, but before the first onload event is called.
Rating: 3