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

Asynchronous validation functions causing missed input #1073

Open
malee31 opened this issue Dec 28, 2021 · 0 comments
Open

Asynchronous validation functions causing missed input #1073

malee31 opened this issue Dec 28, 2021 · 0 comments

Comments

@malee31
Copy link

malee31 commented Dec 28, 2021

May be related to Issue #912
I noticed that after running a prompt with an asynchronous validate function, a following prompt will miss a line of input and require input twice due to the first line being ignored.

I wrote a simple script with this behavior and attached it below. The first two prompts will run fine but the final one (must type "done" into it) will miss the first line of input. Pressing an arrow/any key after pressing enter will cause the prompt to re-render and wait for a proper answer again.

Device details:
OS: Windows 11
Terminal: PowerShell
Node: 16.13.1
Inquirer: ^8.2.0 (current latest)

const inquirer = require("inquirer");

async function sleep(time) {
	return new Promise(resolve => setTimeout(resolve, time));
}

(async() => {
	let res = await inquirer.prompt({
		name: "val",
		message: "Prompt 1 - Press Anything",
		type: "input",
		validate: async() => {
			await sleep(1000);
			return true;
		}
	});
	console.log(`Result 1: [${res.val}]`);

	res = await inquirer.prompt({
		name: "val",
		message: "Prompt 2 - Press Anything",
		type: "input"
	});
	console.log(`Result 3: [${res.val}]`);

	res = await inquirer.prompt({
		name: "done",
		message: "Prompt 3 - Type done",
		type: "input",
		validate: async val => {
			await sleep(1000);
			return val.toLowerCase() === "done";
		}
	});
	console.log(`Result 3: [${res.done}]`);
})();

Result as a screenshot

image

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