From 5516adec57d5cee29e636ca43b4155e6279c7e1d Mon Sep 17 00:00:00 2001 From: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> Date: Tue, 13 Dec 2022 19:16:51 -0800 Subject: Avoid creating closure --- src/bun.js/builtins/js/ProcessObjectInternals.js | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'src/bun.js/builtins/js/ProcessObjectInternals.js') diff --git a/src/bun.js/builtins/js/ProcessObjectInternals.js b/src/bun.js/builtins/js/ProcessObjectInternals.js index 5c5fab9ea..87bb07b95 100644 --- a/src/bun.js/builtins/js/ProcessObjectInternals.js +++ b/src/bun.js/builtins/js/ProcessObjectInternals.js @@ -534,20 +534,26 @@ function getStdinStream(fd, rawRequire, Bun) { } } - _read(size) { - this.#reader.read().then((data) => { - if (data.done) { + async #readInternal() { + try { + const { done, value } = await this.#reader.read(); + + if (!done) { + this.push(value); + } else { this.push(null); this.pause(); this.#readable = false; this.#onFinished(); - } else { - this.push(data.value); } - }).catch((err) => { + } catch (err) { this.#readable = false; this.#onFinished(err); - }); + } + } + + _read(size) { + this.#readInternal(); } #constructWriteStream() { -- cgit v1.2.3