From ad054f68abc366a496449a4e568e2797b73f3dcf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Norte?= Date: Sun, 1 Mar 2015 00:36:51 +0100 Subject: [PATCH 1/2] Added failing test --- test/test-publish.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/test/test-publish.js b/test/test-publish.js index db00eb5..16b2fcf 100644 --- a/test/test-publish.js +++ b/test/test-publish.js @@ -160,6 +160,27 @@ delete PubSub.immediateExceptions; }, + "publish method should fail immediately on exceptions in namespaces when immediateExceptions is true" : function(){ + var func1 = function(){ + throw('some error'); + }, + spy1 = this.spy(); + + PubSub.subscribe( 'buy', func1 ); + PubSub.subscribe( 'buy', spy1 ); + + PubSub.immediateExceptions = true; + + assert.exception( function(){ + PubSub.publishSync( 'buy.tomatoes', 'some data' ); + }); + + refute( spy1.called ); + + // make sure we restore PubSub to it's original state + delete PubSub.immediateExceptions; + }, + "publish should call all subscribers, even when there are unsubscriptions within" : function(done){ var topic = TestHelper.getUniqueString(), spy1 = this.spy(), From 138d8796fa25cce3b25c0f8a42d4a9a0e1264728 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Norte?= Date: Sun, 1 Mar 2015 00:38:11 +0100 Subject: [PATCH 2/2] Added immediateExceptions flag to hierarchy deliveries --- src/pubsub.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pubsub.js b/src/pubsub.js index 3cec0a8..e021a2c 100755 --- a/src/pubsub.js +++ b/src/pubsub.js @@ -88,7 +88,7 @@ https://github.com/mroderick/PubSubJS while( position !== -1 ){ topic = topic.substr( 0, position ); position = topic.lastIndexOf('.'); - deliverMessage( message, topic, data ); + deliverMessage( message, topic, data, immediateExceptions ); } }; }