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

Add support for the "question" method #3

Closed
machineghost opened this issue Feb 8, 2018 · 3 comments
Closed

Add support for the "question" method #3

machineghost opened this issue Feb 8, 2018 · 3 comments
Assignees

Comments

@machineghost
Copy link

machineghost commented Feb 8, 2018

This library is great, except it seems to have left out a key part of the readline API out: the question method.

Currently if I log the method in readline-promise I see:

function (query, cb) {
  if (typeof cb === 'function') {
    if (this._questionCallback) {
      this.prompt();
    } else {
      this._oldPrompt = this._prompt;
      this.setPrompt(query);
      this._questionCallback = cb;
      this.prompt();
    }
  }
} 

In other words, I see the normal (readline not readline-promise) style question function which takes a callback. It would seem more appropriate for the readline-promise version to be something like:

function (query) {
  if (this._questionCallback) {
    return this.prompt();
  } else {
    this._oldPrompt = this._prompt;
    this.setPrompt(query);
    return this.prompt();
  }
} 

(The above assumes prompt returns a promise; if not some further adjustment might be necessary.)

Is something like this possible/desired?

@machineghost machineghost changed the title add support for question? Add support for the "question" method Feb 8, 2018
@bhoriuchi
Copy link
Owner

bhoriuchi commented Feb 8, 2018

In general, methods with callbacks are easy to promisify whereas streams take a bit more work. I can add a questionAsync method that would just be something like

function questionAsync(query) {
  return new Promise(resolve => {
    rl.question(query, resolve)
  })
}

@machineghost
Copy link
Author

That would be great.

@bhoriuchi bhoriuchi self-assigned this Feb 8, 2018
@bhoriuchi
Copy link
Owner

v1.0.3 has been published with the questionAsync method

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants