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
Now try feeding data with multiple lines as one batch to stdin:
echo -e "line 1\nline 2\n" | node script.js
How often does it reproduce? Is there a required condition?
No, it appears each time you try to process multiple lines of input at once using promise version of readline.
What is the expected behavior? Why is that the expected behavior?
What you get is not what you expect, all lines of input land to first variable which is input1, instead of assigning correspondingly to input1 and input2. This is due to first rl.question consuming all event data of the stdin. One way of solving this is queueing the inputs in one place, so that results would be correctly resolved to all rl.question calls, see prototype proposition bellow.
What do you see instead?
This is just a scratch, showing that problem exists, not the best approach right here:
The better solution would be feeding stdout stream line by line to corresponding questions, so that the order of input and output would not be violated, in case above the order is following:
Enter input1:
1
2
Enter input2:
input1: 1
input2: 2
First input being read, and only then second question comes up, the right output should be:
Enter input1:
1
Enter input2:
2
input1: 1
input2: 2
Additional information
No response
The text was updated successfully, but these errors were encountered:
Version
v20.17.0
Platform
Subsystem
No response
What steps will reproduce the bug?
Start with the following code:
Now try feeding data with multiple lines as one batch to stdin:
How often does it reproduce? Is there a required condition?
No, it appears each time you try to process multiple lines of input at once using promise version of readline.
What is the expected behavior? Why is that the expected behavior?
What you get is not what you expect, all lines of input land to first variable which is input1, instead of assigning correspondingly to input1 and input2. This is due to first rl.question consuming all event data of the stdin. One way of solving this is queueing the inputs in one place, so that results would be correctly resolved to all rl.question calls, see prototype proposition bellow.
What do you see instead?
This is just a scratch, showing that problem exists, not the best approach right here:
The better solution would be feeding stdout stream line by line to corresponding questions, so that the order of input and output would not be violated, in case above the order is following:
First input being read, and only then second question comes up, the right output should be:
Additional information
No response
The text was updated successfully, but these errors were encountered: