Skip to content

Commit

Permalink
Add a fallback for missing subscribers
Browse files Browse the repository at this point in the history
  • Loading branch information
haeky committed Feb 25, 2025
1 parent 2d3c3c2 commit c4c8857
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions assets/pubsub.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ function subscribe(eventName, callback) {

function publish(eventName, data) {
if (subscribers[eventName]) {
console.log(eventName);
const promises = subscribers[eventName]
.map((callback) => callback(data))
return Promise.all(promises);
} else {
return Promise.resolve()
}
}

0 comments on commit c4c8857

Please sign in to comment.