Skip to content
This repository has been archived by the owner on Apr 15, 2019. It is now read-only.

Commit

Permalink
♻️ Refactor timeoutPromise
Browse files Browse the repository at this point in the history
  • Loading branch information
mitsujutsu committed Oct 4, 2018
1 parent a75b7dc commit 11ef6c9
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/utils/input/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,17 @@ export const splitSource = source => {
};
};

const timeoutPromise = readFromStd =>
new Promise((resolve, reject) => {
const id = setTimeout(() => {
clearTimeout(id);
if (stdinIsTTY()) {
reject(new Error(`Timed out after ${DEFAULT_TIMEOUT} ms`));
}
resolve(readFromStd);
}, DEFAULT_TIMEOUT);
});
const timeoutPromise = async readFromStd => {
try {
await (() =>
new Promise(([reject]) => setTimeout(reject, DEFAULT_TIMEOUT)))();
} catch (e) {
if (stdinIsTTY()) {
throw new Error(`Timed out after ${DEFAULT_TIMEOUT} ms`);
}
}
return readFromStd;
};

export const getRawStdIn = () => {
const readFromStd = new Promise(resolve => {
Expand Down

0 comments on commit 11ef6c9

Please sign in to comment.