Skip to content
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

readline: add readline.promises #28407

Closed
wants to merge 8 commits into from
Closed

Conversation

cjihrig
Copy link
Contributor

@cjihrig cjihrig commented Jun 24, 2019

This PR adds an experimental readline.promises, similar to the ones in the dns and fs modules. The completer() argument to the Interface class, and the question() are the primary differences from the callback based implementation.

I also took this opportunity to freshen up the readline code a bit (formatting comments, replacing var with let/const, etc.).

This is still WIP because I need to port the documentation.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

@nodejs-github-bot nodejs-github-bot added the lib / src Issues and PRs related to general changes in the lib or src directory. label Jun 24, 2019
@addaleax addaleax added readline Issues and PRs related to the built-in readline module. semver-minor PRs that contain new features and should be released in the next minor version. wip Issues and PRs that are still a work in progress. and removed lib / src Issues and PRs related to general changes in the lib or src directory. labels Jun 24, 2019
@cjihrig cjihrig removed the wip Issues and PRs that are still a work in progress. label Jun 25, 2019
@cjihrig cjihrig changed the title WIP: readline: add readline.promises readline: add readline.promises Jun 25, 2019
@cjihrig
Copy link
Contributor Author

cjihrig commented Jun 25, 2019

The documentation is ported. This is ready for review.

doc/api/readline.md Outdated Show resolved Hide resolved
doc/api/readline.md Outdated Show resolved Hide resolved
doc/api/readline.md Outdated Show resolved Hide resolved
doc/api/readline.md Outdated Show resolved Hide resolved
doc/api/readline.md Outdated Show resolved Hide resolved
@cjihrig
Copy link
Contributor Author

cjihrig commented Jun 27, 2019

Thanks @vsemozhetbyt. I've incorporated your suggestions.

@nodejs-github-bot

This comment has been minimized.

@nodejs-github-bot

This comment has been minimized.

@nodejs-github-bot

This comment has been minimized.

@nodejs-github-bot

This comment has been minimized.

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@cjihrig
Copy link
Contributor Author

cjihrig commented Jun 28, 2019

Ping for reviews

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

lib/internal/readline/utils.js Outdated Show resolved Hide resolved
lib/readline.js Outdated Show resolved Hide resolved
createInterface,
cursorTo,
emitKeypressEvents,
moveCursor
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think all of these, except for Interface and emitKeypressEvents, are async operations because they write to the underlying stream. Should we account for that by making them return Promises?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@addaleax I've been thinking about this. I'm a little torn. Returning a Promise does make sense. But why doesn't the current readline implementation consider the write() callback at all? The return value of write() is also not considered in either implementation currently.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But why doesn't the current readline implementation consider the write() callback at all? The return value of write() is also not considered in either implementation currently.

Because inconsistent API design is one of Node’s big weaknesses, sadly… (And probably also because Node follows a “small writes work synchronously 99 % of the time” model, with all the pain that comes with the other 1 %).

But yeah, I’d prefer not repeating past mistakes. The return value is something I hadn’t considered yet, to be honest, but I’d probably give the write callback preference?

This commit moves lib/internal/readline.js to
lib/internal/readline/utils.js. This is in preparation of
adding a readline.promises implementation.
This commit moves the readline Interface class to its own
file. All other readline logic is moved into the internal
readline utils file.
This commit defines a named constant instead of using a mix of
2 ** 16 and 0X10000 throughout the code.
This changes the last two `var` uses in the readline code
to `let`.
This commit refactors _tabComplete() to only pause the interface,
call the completer() function, and then call another function to
handle the results. This will make it simpler to support a
promises based completer() function without duplicating much
code.
This commit moves all Interface() constructor argument parsing
into a helper function.
This commit exposes a Promise based version of the readline API.
Remove the readline.promises experimental warning per
PR review comment.
@nodejs-github-bot
Copy link
Collaborator

nodejs-github-bot commented Jul 10, 2019

CI: https://ci.nodejs.org/job/node-test-pull-request/24360/

EDIT(cjihrig): CI was yellow.

@addaleax
Copy link
Member

@cjihrig Was this closed intentionally?

@cjihrig
Copy link
Contributor Author

cjihrig commented Jul 11, 2019

Was this closed intentionally?

Yes. I want to do some work on the current readline module before revisiting this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
readline Issues and PRs related to the built-in readline module. semver-minor PRs that contain new features and should be released in the next minor version.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants