From c136a7dbe23107b0248245efdb5b075437e4b9e3 Mon Sep 17 00:00:00 2001 From: Philipe Navarro Date: Fri, 1 Jun 2018 10:43:27 -0700 Subject: [PATCH 1/2] fix: prompt timeout --- src/prompt.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/prompt.ts b/src/prompt.ts index fbffe2f9..3f84c51b 100644 --- a/src/prompt.ts +++ b/src/prompt.ts @@ -72,15 +72,17 @@ function normal(options: IPromptConfig, retries = 100): Promise { process.stdin.setEncoding('utf8') process.stderr.write(options.prompt) process.stdin.resume() + let timer = setTimeout(() => reject(), options.timeout || 10000) process.stdin.once('data', data => { process.stdin.pause() data = data.trim() if (!options.default && options.required && data === '') { + timer.unref() resolve(normal(options, retries - 1)) } else { + timer.unref() resolve(data || options.default) } }) - setTimeout(() => reject(), options.timeout || 10000) }) } From a9e81caab65d590a16f9e439d827c8702251737a Mon Sep 17 00:00:00 2001 From: Philipe Navarro Date: Fri, 1 Jun 2018 11:07:53 -0700 Subject: [PATCH 2/2] fix --- src/prompt.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/prompt.ts b/src/prompt.ts index 3f84c51b..b64b4a8a 100644 --- a/src/prompt.ts +++ b/src/prompt.ts @@ -72,17 +72,15 @@ function normal(options: IPromptConfig, retries = 100): Promise { process.stdin.setEncoding('utf8') process.stderr.write(options.prompt) process.stdin.resume() - let timer = setTimeout(() => reject(), options.timeout || 10000) process.stdin.once('data', data => { process.stdin.pause() data = data.trim() if (!options.default && options.required && data === '') { - timer.unref() resolve(normal(options, retries - 1)) } else { - timer.unref() resolve(data || options.default) } }) + setTimeout(() => reject(), options.timeout || 10000).unref() }) }