UPDATE: This is useless. Please see this comment.
There have been a variety of occasions where I only want one instance of the Request object, but want to make sure that every request I attempt gets run without canceling another, or screwing around with onCompletes. The following is a rather simple implement that takes care of this problem:
code!
Request.implement({ queue: function(sendArg){ if(!$defined(this.queued)) this.queued = []; this.queued.push(sendArg); this.processQueue(); }, processQueue: function(){ if(this.timer) $clear(this.timer); if (!this.check()) this.timer = this.processQueue.delay(250, this); else { if ($defined(this.queued[0])) { this.send(this.queued.shift()); this.processQueue(); } else this.fireEvent('onQueueEmpty'); } } });
This will basically stack requests and send them in the order received. If there is no stack, the request will be sent immediately.
The usage is the same as the normal Request send method, however there is now an onQueueEmpty event to tell when all requests in the queue have been sent.