-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[Feature]: inquirer/search - debounce support #1490
Comments
I think you could simplify that using the promise interface of import { setTimeout } from 'node:timers/promises';
import { search } from '@inquirer/prompts';
const answer = await search({
message: 'Select an npm package',
source: async (input, { signal }) => {
await setTimeout(300);
if (signal.aborted) return [];
// Do the search
fetch(...)
},
}); IMO that's a simple piece of code that can be implemented in the user land. Let me know if that'd work (I'll document the pattern as a recipe.) |
@SBoudrias Yes that's a nice recipe! Thanks |
Whats this supposed to do exactly? I have an issue where if i type too fast, the result from an old search string (current input minus 1 character) are shown |
Debouncing will reduce load on API calls, ignoring certain keystroke until the user is done typing. If you're interacting with external service this can be important. But it's not there by default ATM since not every use-case rely on network calls. Side note, if you think you found a race condition, I'd be interested in reviewing a reproductible case. There shouldn't be race condition - so if there's one, it's a bug. |
Description:
It would be good to have a native debouce value for the search module. Currently I am doing this to handle it:
The text was updated successfully, but these errors were encountered: