diff options
author | 2023-02-03 16:33:02 -0800 | |
---|---|---|
committer | 2023-02-03 16:39:16 -0800 | |
commit | 7d386bf1f1c7cbcf58b31fcc4c8e8d945483518e (patch) | |
tree | ebb830f1a3811a03ba480cb5dbdc0295c4bdf987 /src/bun.js/api/bun.zig | |
parent | 164cd774f7e8075b1f3a2948c141d27b01f3d542 (diff) | |
download | bun-7d386bf1f1c7cbcf58b31fcc4c8e8d945483518e.tar.gz bun-7d386bf1f1c7cbcf58b31fcc4c8e8d945483518e.tar.zst bun-7d386bf1f1c7cbcf58b31fcc4c8e8d945483518e.zip |
Introduce `await Bun.sleep(ms)`
Diffstat (limited to 'src/bun.js/api/bun.zig')
-rw-r--r-- | src/bun.js/api/bun.zig | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/src/bun.js/api/bun.zig b/src/bun.js/api/bun.zig index 0b47bea27..d7e42dc90 100644 --- a/src/bun.js/api/bun.zig +++ b/src/bun.js/api/bun.zig @@ -2873,19 +2873,25 @@ pub const Timer = struct { const callback = this.callback.get() orelse @panic("Expected CallbackJob to have a callback function"); if (this.arguments.trySwap()) |arguments| { - const count = arguments.getLengthOfArray(globalThis); - if (count > 0) { - if (count > args_buf.len) { - args = bun.default_allocator.alloc(JSC.JSValue, count) catch unreachable; - args_needs_deinit = true; - } else { - args = args_buf[0..count]; - } - var arg = args.ptr; - var i: u32 = 0; - while (i < count) : (i += 1) { - arg[0] = JSC.JSObject.getIndex(arguments, globalThis, @truncate(u32, i)); - arg += 1; + // Bun.sleep passes a Promise + if (arguments.jsType() == .JSPromise) { + args_buf[0] = arguments; + args = args_buf[0..1]; + } else { + const count = arguments.getLengthOfArray(globalThis); + if (count > 0) { + if (count > args_buf.len) { + args = bun.default_allocator.alloc(JSC.JSValue, count) catch unreachable; + args_needs_deinit = true; + } else { + args = args_buf[0..count]; + } + var arg = args.ptr; + var i: u32 = 0; + while (i < count) : (i += 1) { + arg[0] = JSC.JSObject.getIndex(arguments, globalThis, @truncate(u32, i)); + arg += 1; + } } } } |