-
Notifications
You must be signed in to change notification settings - Fork 30
Conversation
6cd0396
to
a75b7dc
Compare
src/utils/input/utils.js
Outdated
if (stdinIsTTY()) { | ||
reject(new Error(`Timed out after ${DEFAULT_TIMEOUT} ms`)); | ||
} | ||
resolve(readFromStd); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's strange to resolve
a Promise here.
dcd04ed
to
11ef6c9
Compare
src/utils/input/utils.js
Outdated
@@ -60,7 +64,7 @@ export const getRawStdIn = () => { | |||
.on('line', line => lines.push(line)) | |||
.on('close', () => resolve(lines)); | |||
}); | |||
return Promise.race([readFromStd, timeoutPromise(DEFAULT_TIMEOUT)]); | |||
return Promise.race([readFromStd, timeoutPromise(readFromStd)]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we wrap the promise, I think we can remove Promise.race
src/utils/input/utils.js
Outdated
const timeoutPromise = async readFromStd => { | ||
try { | ||
await (() => | ||
new Promise(([reject]) => setTimeout(reject, DEFAULT_TIMEOUT)))(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we clearTimeout
in normal scenario?
Also, this doesn't throw error, so what are we doing for try-catch
...? do we need Promise
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't thought about how to clean it up, but intended functionality is something like this?
Maybe we can chain this function to handleClose
part so it uses getRawStdIn
in getStdIn
and it just handles the output nicely?
const readFromStd = new Promise((resolve, reject) => {
const rl = readline.createInterface({ input: process.stdin });
const lines = [];
rl
.on('line', line => lines.push(line))
.on('close', () => resolve(lines));
const id = setTimeout(() => {
clearTimeout(id);
if (stdinIsTTY()) {
reject(new Error(`Timed out after ${DEFAULT_TIMEOUT} ms`));
} else {
resolve(lines);
}
}, DEFAULT_TIMEOUT);
});
return readFromStd;
11ef6c9
to
34e87d8
Compare
src/utils/input/utils.js
Outdated
@@ -109,7 +98,7 @@ export const getStdIn = ({ | |||
|
|||
return rl.on('line', line => lines.push(line)).on('close', handleClose); | |||
}); | |||
return Promise.race([readFromStd, timeoutPromise(DEFAULT_TIMEOUT)]); | |||
return Promise.resolve(readFromStd); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you should just return readFromStd
here
src/utils/input/utils.js
Outdated
if (stdinIsTTY()) { | ||
return reject(new Error(`Timed out after ${DEFAULT_TIMEOUT} ms`)); | ||
} | ||
return resolve(lines); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this content of resolve
should be consistent with the other resolve
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's probably easier to change handleClose
to function (line: string[]) => { passphrase, second... }
, then call from close
event and timeout
event
34e87d8
to
a3f12ed
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM GJ
a3f12ed
to
fcf52ff
Compare
What was the problem?
Related to PR: #622
Race condition in
getRawStdin
causing inconsistent results when piping.How did I fix it?
Update getStdin func, remove getRawStdin and promise.race.
How to test it?
./bin/run transaction:create -t=0 100 100L --passphrase="pass:123" | ./bin/run transaction:sign --passphrase="pass:123"
Review checklist