Skip to content
This repository has been archived by the owner on Feb 1, 2022. It is now read-only.

fix: prompt timeout #35

Merged
merged 2 commits into from
Jun 1, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,17 @@ function normal(options: IPromptConfig, retries = 100): Promise<string> {
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't you just change this line to setTimeout(() => reject(), options.timeout || 10000).unref()?

})
}