Bug in mstats.pubsub.js

Aug 4, 2011 at 3:00 PM

So I was playing around with this project. I like it, but I found a nice little bug in the publish method. Not the big deal and easy to fix.. The problem is where the count in incremented, line 29 of mstats.pubsub.js

 

 

 if (queue[eventName][idx]) {
                        context = queue[eventName][idx].context || this;
                        queue[eventName][idx].callback.call(context, data);
                        idx += 1;

It works great unless, you are like me and subscribe to a event that has a JavaScript error in it. Then what happens is the count is never is never incremented, you get in a infinite loop of errors. Anyway, I made a simple update to fix.I did not want to use a try/catch because I wanted to see the error, so I just moved the idx += 1; Anyway, tell me what you guys think.

  that.publish = function (eventName, data) {
            var context, intervalId, idx = 0;
            if (queue[eventName]) {
                intervalId = setInterval(function () {
                    idx += 1
                    if (queue[eventName][idx - 1]) {
                        context = queue[eventName][idx - 1].context || this;
                        queue[eventName][idx - 1].callback.call(context, data);
                    } else {
                        clearInterval(intervalId);
                    }
                }, 0);

            }
        };

Jon Z


Developer
Aug 5, 2011 at 6:50 PM

Hi Jon,

Thank you for reporting this. We have created a work item in the Issue Tracker about it. It would be helpful if you could add a repro sample application that portrays this problem in the work item we've created, so as to have a faster means of confirming this for the Silk team.

I hope you find this helpful.

Guido Leandro Maliandi
http://blogs.southworks.net/gmaliandi

Aug 8, 2011 at 6:40 PM

I added a app to the ticket.