RequestQueue
A simple queue for XMLHttpRequests or other async functions. Optimized for Greasemonkey GM_xmlhttpRequests
Install / Use
/learn @cvzi/RequestQueueREADME
RequestQueue
A simple queue for XMLHttpRequests or other async functions. Optimized for Greasemonkey GM_xmlhttpRequests
Documentation
new RequestQueue([maxParallel[, maxTotal]])
Create queue object
- maxParallel defaults to 1 i.e. no paralllel requests
- maxTotal defaults to unlimited
RequestQueue.prototype.add(req[, fun[, thisArg]])
Schedule a request
- req An object that is the only argument of fun. This will be extended and therefore must be mutable. At least one of the following methods onload, onerror or onabort must be implemented.
- fun
defaults to
GM_xmlhttpRequest - thisArg The value of this provided for the call to fun. Keep strict mode in mind!
Results in a call like this: thisArg.fun(req)
RequestQueue.prototype.abortRunning()
Abort running requests
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()
Abort pending requests
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.
Version history
- Version 6
- Support for Greasemonkey version 4 and Firefox version 57
- Version 5
- New methods: resetTotal(), hasReachedTotal(), hasRunning()
- Version 4
- Fix for XMLHttpRequest.abort()
- Version 3
- Fix for Chrome
- Version 2
- Fix for Firefox 36.0
- Version 1
- initial version
Related Skills
node-connect
349.0kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
109.4kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
349.0kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
349.0kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
