You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Nov 2, 2020. It is now read-only.
What I want to do:
For my application I have multiple classes that each get created with access to the wss object. I want them to handle different sockets, but to avoid having to modify my main files, I have a connection handler in each of the classes to filter out the sockets they want.
Expected behaviour:
When I have multiple event handlers listening to the same event I would expect them all to get executed with the same data.
Observed behaviour:
Only 1 wss.on('connection') handler gets executed. The rest are ignored.
Workaround:
Have 1 connection handler in the main thread and loop over all my socket handlers.
The text was updated successfully, but these errors were encountered:
Unfortunate it is a part of design to have only one listener on single event as having more then one is inefficient. The same principal as in uWS library check this at the end of the page.
We are trying to make the framework as fast and minimalistic as possible with less performance overhead.
I believe the best solution in you case will be to listen on connection event and call another event emitter with many listeners to propagate this event to your events for example.
But do you really save that much on performance by not allowing multiple event listeners? Wouldn't it be just as fast if you allowed multiple but printed a warning about not being good for performance? I feel that my current workaround of just running more code and loops in the one event handler is probably going to be worse.
I will look in to that and do some benches, if everything works out well and i don't need to change core too much i may add this functionality to listen many instead of one when is needed.
Submitting
What I want to do:
For my application I have multiple classes that each get created with access to the wss object. I want them to handle different sockets, but to avoid having to modify my main files, I have a connection handler in each of the classes to filter out the sockets they want.
Expected behaviour:
When I have multiple event handlers listening to the same event I would expect them all to get executed with the same data.
Observed behaviour:
Only 1
wss.on('connection')
handler gets executed. The rest are ignored.Workaround:
Have 1 connection handler in the main thread and loop over all my socket handlers.
The text was updated successfully, but these errors were encountered: