From d1834b5a92669c51ff73ce8f6aa3a80895270030 Mon Sep 17 00:00:00 2001 From: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> Date: Wed, 14 Dec 2022 18:05:27 -0800 Subject: [process.stdin] Support reading from process.stdin in the same tick --- src/bun.js/builtins/js/ProcessObjectInternals.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'src/bun.js/builtins/js') 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(); -- cgit v1.2.3