-
Notifications
You must be signed in to change notification settings - Fork 30.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
repl: limit line processing to one at a time #39392
base: main
Are you sure you want to change the base?
Conversation
dca73eb
to
d4f88a0
Compare
@guybedford Feel free to take a look at this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please clarify if any of the changes here are major / breaking changes?
//cc @nodejs/repl for more reviewers.
I'd like to add the output of |
@ejose19 I'm not aware of any debug stream testing, but there might be some examples in the existing tests directory to be found. Alternatively setting up something custom could be worthwhile unless someone else can clarify further here. |
@guybedford I had to replace the original |
5b3025e
to
d4d05b3
Compare
@ejose19 if we're doing a major change here anyway, should we also support |
@guybedford That would require a major overhaul in the tests, since most of them expect the output right after writing the input, which is the case for sync code. But if So even if using async |
@ejose19 what I mean is branching the API on sync / async handling with: eval: () => Promise | undefined where the undefined case is treated as sync, and the promise case is treated as the async situation, for example rather than enforcing the callback. That's not the exact approach but along those lines I mean. |
@guybedford you mean something like this? const evalResult = self.eval(evalCmd, self.context, getREPLResourceName(), finish);
if (evalResult !== undefined) {
if (!(evalResult instanceof Promise)) {
self._domain.emit('error', 'eval must return "undefined" or a "Promise"');
return;
}
(async () => {
const { error, result } = await evalResult;
finish(error, result);
})();
} |
Yes that seems like the sort of approach if you agree it could make sense. Would this also allow this PR to be done in a backwards compatible way perhaps? Perhaps we should consider being more lenient on the return value to be safe in that case? Either way wrt the validation could work for me though. |
I don't think it can be made backward compatible, we can't assume Lines 606 to 623 in 44e3822
If other projects based their Ideally, |
@ejose19 I guess I'm still not clear on how the callback can be optional currently. But if the current eval doesn't return a value, then allowing the current eval to return a promise would be a backwards-compatible extension. Then allowing that promise to be a completion based callback that fits the requirements you needed for the async callback could also be a way to possible shoehorn this feature in a backwards compatible way (separate to the explicit callback mechanism). Again I'm not super clear on the details of this code, so fill me in where I'm wrong :) |
@guybedford If something like this is added to the PR, then
For any code that is not returning a So what I mean is, while we can improve the "handling" of |
So because the invariant of per-line processing requires all eval implementations to conform, there's no middle ground here on creating a backwards compatible subset, got it. In that case moving ahead with this as-is seems fine to me. |
One other question - what will be the outcome for eval implementations that do not call the callback? Will it just stall? |
Correct, for most commands that will be the outcome, unless other event resets the |
@ejose19 another option could be to check the function length of the |
@guybedford Ok, that's an interesting approach, but it's enough for this to be considered non breaking? What about consumers that defined the argument but never called it? |
I tried with that, and it seems this line: Line 632 in 44e3822
makes the function to have a different length than the original (0 vs 4 for |
Ok, thanks for hearing me out on these questions, agreed the major is best then with the callback being enforced. |
Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
The CI failures here need to be investigated. They appear they might b relevant to the change |
Fixes: #39387