From 1b7b37232eb0e9e36e9d5f693e14a5d9bc74efbd Mon Sep 17 00:00:00 2001 From: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> Date: Fri, 2 Dec 2022 22:30:04 -0800 Subject: Run promise before callback --- src/bun.js/api/bun/subprocess.zig | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/bun.js/api/bun/subprocess.zig b/src/bun.js/api/bun/subprocess.zig index 75f1eb05c..ba1aab7ff 100644 --- a/src/bun.js/api/bun/subprocess.zig +++ b/src/bun.js/api/bun/subprocess.zig @@ -1471,6 +1471,19 @@ pub const Subprocess = struct { defer this.updateHasPendingActivity(); this.has_waitpid_task = false; + if (this.exit_promise.trySwap()) |promise| { + if (this.exit_code) |code| { + promise.asPromise().?.resolve(globalThis, JSValue.jsNumber(code)); + } else if (this.waitpid_err) |err| { + this.waitpid_err = null; + promise.asPromise().?.reject(globalThis, err.toJSC(globalThis)); + } else { + // crash in debug mode + if (comptime Environment.allow_assert) + unreachable; + } + } + if (this.on_exit_callback.trySwap()) |callback| { const exit_value: JSValue = if (this.exit_code) |code| JSC.JSValue.jsNumber(code) @@ -1498,19 +1511,6 @@ pub const Subprocess = struct { } } - if (this.exit_promise.trySwap()) |promise| { - if (this.exit_code) |code| { - promise.asPromise().?.resolve(globalThis, JSValue.jsNumber(code)); - } else if (this.waitpid_err) |err| { - this.waitpid_err = null; - promise.asPromise().?.reject(globalThis, err.toJSC(globalThis)); - } else { - // crash in debug mode - if (comptime Environment.allow_assert) - unreachable; - } - } - this.unref(); } -- cgit v1.2.3