Best practices for multiple listener on single event

events are published while making chat with XMPP server, server published events like…

this.client.on('message:sent', function (msg) {
      console.log("message:sent");
      console.log(msg);
);

 this.client.on('pubsub:event', function (msg) {
      console.log("pubsub:event");
      console.log(msg);
);

 this.client.on('message', function (msg) {
      console.log("message");
      console.log(msg);
      );

this.client.on('stanza', function (msg) {
      console.log("stanza")

      console.log(msg);
    });

what will be impact on app if i use same event listeners multiple times? does it will increase the load on application or anything else problem occurred? or any other side effect? power consumption or resource utilise related issue?

I would turn the event listener into an Observable, and then use the multicast operator to send the message to multiple subscriptions at once. That way, you’re putting as little work on the server as possible. The downside to this approach is that if you haven’t used Observables before, you’re going to have to do some reading. But once you “get it,” the solution will be super clean.

1 Like