diff options
author | 2022-12-14 18:05:27 -0800 | |
---|---|---|
committer | 2022-12-15 16:28:47 -0800 | |
commit | d1834b5a92669c51ff73ce8f6aa3a80895270030 (patch) | |
tree | e61514e1e5e2c84098089ccf1c8c25e38cd10aa9 /src/bun.js/builtins/js/ProcessObjectInternals.js | |
parent | e38a3e5d85dd3b07b0ed61981e874907fa90296b (diff) | |
download | bun-d1834b5a92669c51ff73ce8f6aa3a80895270030.tar.gz bun-d1834b5a92669c51ff73ce8f6aa3a80895270030.tar.zst bun-d1834b5a92669c51ff73ce8f6aa3a80895270030.zip |
[process.stdin] Support reading from process.stdin in the same tick
Diffstat (limited to 'src/bun.js/builtins/js/ProcessObjectInternals.js')
-rw-r--r-- | src/bun.js/builtins/js/ProcessObjectInternals.js | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/src/bun.js/builtins/js/ProcessObjectInternals.js b/src/bun.js/builtins/js/ProcessObjectInternals.js index 2353f6b7e..2a3c67242 100644 --- a/src/bun.js/builtins/js/ProcessObjectInternals.js +++ b/src/bun.js/builtins/js/ProcessObjectInternals.js @@ -444,6 +444,7 @@ function getStdinStream(fd, rawRequire, Bun) { var StdinStream = class StdinStream extends Duplex { #reader; // TODO: investigate https://github.com/oven-sh/bun/issues/1607 + #readRef; #writeStream; @@ -531,10 +532,24 @@ function getStdinStream(fd, rawRequire, Bun) { async #readInternal() { try { - const { done, value } = await this.#reader.read(); + var done, value; + const read = this.#reader.readMany(); + + // read same-tick if possible + if (!read?.then) { + ({ done, value } = read); + } else { + ({ done, value } = await read); + } if (!done) { - this.push(value); + this.push(value[0]); + + // shouldn't actually happen, but just in case + const length = value.length; + for (let i = 1; i < length; i++) { + this.push(value[i]); + } } else { this.push(null); this.pause(); |