Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

_fireSubsribers stops on first error #63

Closed
ntgn81 opened this Issue · 1 comment

1 participant

@ntgn81

When one of the subscribers throws unhandled exceptions, none of the subscribers will be called.

Here is a sample:

http://jsfiddle.net/ntgn81/ww9Tw/

I'm not sure if you guys considere this as an issue, but if you do, here is a possible solution:

    function _fireSubscribers(channel, payload){
        if(_pubsub_observers[channel]){
            var errors = [];
            for(var i=0, len = _pubsub_observers[channel].length; i<len; i++){
                // send immutable data that can't be modified by listeners
                try{
                  _pubsub_observers[channel][i](channel, JSON.parse(JSON.stringify(payload)));
                }
                catch(e){
                  // catch errors thrown by subsribers
                  errors.push(e);
                }
            }
            if (errors.length > 0){
              for (var j = 0; j < errors.length; j++){
                // Throw a new error with some nice message that concatenates the errors
              }
            }
        }
    }

Thanks!

@andris9 andris9 closed this in 2cdee81
@ntgn81

Thanks! We had older version of jStorage.

Can we rethrow the error/errors after all callbacks are called?

It would make developing observer's code much easier.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.