Skip to content

Commit

Permalink
fix(ext/node): spread args in setImmediate (denoland#22998)
Browse files Browse the repository at this point in the history
Closes denoland#22997

Co-authored-by: Divy Srivastava <[email protected]>
  • Loading branch information
satyarohith and littledivy committed Mar 20, 2024
1 parent 724cdce commit fb0744f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
4 changes: 2 additions & 2 deletions ext/node/polyfills/internal/timers.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ Timeout.prototype[Symbol.toPrimitive] = function () {
};

// Immediate constructor function.
export function Immediate(callback, args) {
this._immediateId = setImmediate_(callback, args);
export function Immediate(callback, ...args) {
this._immediateId = setImmediate_(callback, ...args);
}

// Make sure the linked list only shows the minimal necessary information.
Expand Down
17 changes: 16 additions & 1 deletion tests/unit_node/timers_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Deno.test("[node/timers setInterval]", () => {
}
});

Deno.test("[node/timers setImmediate]", () => {
Deno.test("[node/timers setImmediate]", async () => {
{
const { clearImmediate, setImmediate } = timers;
const imm = setImmediate(() => {});
Expand All @@ -41,6 +41,21 @@ Deno.test("[node/timers setImmediate]", () => {
const imm = timers.setImmediate(() => {});
timers.clearImmediate(imm);
}

{
const deffered = Promise.withResolvers<void>();
const imm = timers.setImmediate(
(a, b) => {
assert(a === 1);
assert(b === 2);
deffered.resolve();
},
1,
2,
);
await deffered;
timers.clearImmediate(imm);
}
});

Deno.test("[node/timers/promises setTimeout]", () => {
Expand Down

0 comments on commit fb0744f

Please sign in to comment.