import{isEmpty}from"./helpers.mjs";class Publisher{constructor(){this.subscriptions={}}subscribe(s,i){isEmpty(this.subscriptions[s])&&(this.subscriptions[s]=[]),this.subscriptions[s].push(i)}unsubscribe(s,i){if(!isEmpty(this.subscriptions[s]))for(let t in this.subscriptions[s])if(this.subscriptions[s][t]==i)return this.subscriptions[s]=this.subscriptions[s].slice(0,t).concat(this.subscriptions[s].slice(t+1)),!0;return!1}async publish(s,i=null){if(!isEmpty(this.subscriptions[s]))for(let t of this.subscriptions[s])await t(i)}}export{Publisher};
