mokkabonna / inquirer-autocomplete-prompt

Autocomplete prompt for inquirer
ISC License
350 stars 82 forks source link

Allow `source` to not be a Promise #22

Closed sindresorhus closed 4 years ago

sindresorhus commented 7 years ago

You might already have gotten the data before the prompt is created. Instead of forcing me to wrap my results in a promise, it would be nice if you just did: Promise.resolve().then(() => opts.source).

Note, I'm intentionally not suggesting Promise.resolve(opts.source()) as that would not catch any synchronous error.

Right now, I'm doing:

source: (answers, input) => Promise.resolve().then(() => filterProcesses(input, processes))
mokkabonna commented 4 years ago

Added a while ago.

mokkabonna commented 4 years ago

Though I had at least. Added it now.

But I had to use a slightly different appraoch to not mess to much with tests or change sync behaviour. With your example the souce call is async, with the oldcode it was not.

So calls it sync like before but wraps it in a promise after the call, and catches sync errors.

https://github.com/mokkabonna/inquirer-autocomplete-prompt/blob/0d3b41c727ad0c87586a7e540816a3c97dd2730c/index.js#L205-L211

Wraps the result anyway even if it is not a promise.