From ac4a8d8c5a876483f531f7db45fc4ae8a6f73d91 Mon Sep 17 00:00:00 2001 From: Leon van Kammen Date: Fri, 15 Mar 2024 10:30:57 +0000 Subject: [PATCH] one reject now halts other promises --- src/3rd/js/pubsub.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/3rd/js/pubsub.js b/src/3rd/js/pubsub.js index 499226f..914b527 100644 --- a/src/3rd/js/pubsub.js +++ b/src/3rd/js/pubsub.js @@ -44,13 +44,13 @@ xrf.emit = function(eventName, data){ return xrf.emit.promise(eventName,data) } -xrf.emit.normal = function(eventName, data) { +xrf.emit.normal = function(eventName, opts) { if( !xrf._listeners ) xrf._listeners = [] var callbacks = xrf._listeners[eventName] if (callbacks) { - for (var i = 0; i < callbacks.length; i++) { + for (var i = 0; i < callbacks.length && !opts.halt; i++) { try{ - callbacks[i](data); + callbacks[i](opts); }catch(e){ console.error(e) } } } @@ -67,7 +67,10 @@ xrf.emit.promise = function(e, opts){ let succesful = opts.promises.reduce( (a,b) => a+b ) if( succesful == opts.promises.length ) resolve(opts) })(opts.promises.length-1), - reject: console.error + reject: (reason) => { + opts.halt = true + console.warn(`'${e}' event rejected: ${reason}`) + } } } xrf.emit.normal(e, opts)