Let's say I have a socket server that listens for a general message and only changes its behavior due to different payloads. For instance:
socket.on('users.get', function(payload) { // retrieve user data // return data that corresponds to the data requested in "payload" socket.emit('users.get', returnData); });
If two emit sockets emit made with the message users.get , how could I distinguish between their return on the client side, assuming they are both made on the same page?
The immediate solution would be to combine the two challenges together, but if such a situation were impossible, how could I manage it otherwise? In this particular case, one call to users.get is made in the page header when the page loads, and another users.get is made from the contents of the page.
Knowing that one call is in the header and the other in the content means that it can work if .once() instead of .on() on the client side, but this is still related to the race status, so I was wondering is there any standard way to handle this.
source share