Hi there,

I want to ensure, that messages are posted in the order, they come in
the stack. My tests at jsFiddle were okay, but with a quick backend
(where the requests are processed very fast) the order is crap.
Sometimes items are posted twice. Is there anybody who can help me
out? Thank you all!

var MessageQueue = Class.create({
        initialize: function(url) {
        this.url = url;
        this.queue = [];
        this.idle = false;
        add: function(message) {
        if (this.idle) {
                console.log("idle, so saved to queue: " + message);
        } else {
                console.log("not idle, so pushed directly: " + message);
        push: function(message) {
        this.idle = true;
        console.log("Ajax.Request will be called now!");
        new Ajax.Request(this.url + "&message=" +
encodeURIComponent(message), {
                onComplete: function() {
                        console.log("successfully sent: " + message);
                if (this.queue.size() > 0) {
                        console.log("queue-size > 0, so enqueue next item");
                        this.push("queued: " + this.queue.shift());
                this.idle = false;

You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptacul...@googlegroups.com.
To unsubscribe from this group, send email to 
For more options, visit this group at 

Reply via email to