Hi there,
is there any best-practice-pattern for implementing a queue for sending ordered requests? I know this hits the logic behind ansynchronous requests, but in special cases one needs queued sending :)
Here is my first attempt:
this.queue = [],
this.sending = false,
send: function(message) {
if (this.sending) {
this.queue.push(message);
} else {
else this.push(message);
}
},
push: function(message) {
this.sending = true;
new Ajax.Request(this.outURL + "&message=" + encodeURIComponent(message), {
onSuccess: function() {
this.sending = false;
if (this.queue.size() > 0) {
this.push("queued: " + this.queue.shift());
}
}.bind(this)
});
},
Is there any better implementation? Thank you in advance :)