How to emit events in loop using socket.io and node.js? #4713
Unanswered
user-redans
asked this question in
Q&A
Replies: 1 comment
-
Hi! You are registering 5 distinct listeners for the var manageEvents_v1 = function(data) {
// ...
// called 5 times
socket.on('feedback_trigger', response);
} You should use the built-in const response = await socket.timeout(10000).emitWithAck('trigger', data); Reference: https://socket.io/docs/v4/client-api/#socketemitwithackeventname-args |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I want to emit 5 events message, in a loop, using socket.io and node.js.
This is what I've tried so far:
HTML client:
Node.JS server:
On server console, I've got follow debug messages:
As you can see, server messages are good, but on client side, I've received something like that:
I don't know why, but all 5 responses are with first value '1'...I can't received all values from 1 to 5.
I expected from server something like this, after every emit event from server to see a message with right value and at the end in browser console, after all 5 loops are over, to display:
After that I need those values outside Promise callback to assign them to another global variable (global_var)
Beta Was this translation helpful? Give feedback.
All reactions