diff --git a/ext/node/polyfills/timers.ts b/ext/node/polyfills/timers.ts index 613b87427cb10e..02f69466eef615 100644 --- a/ext/node/polyfills/timers.ts +++ b/ext/node/polyfills/timers.ts @@ -89,6 +89,22 @@ export function clearImmediate(immediate: Immediate) { clearTimeout_(immediate._immediateId); } +export const promises = { + setTimeout: promisify(setTimeout), + setImmediate: promisify(setImmediate), + setInterval: promisify(setInterval), +}; + +promises.scheduler = { + async wait( + delay: number, + options?: { signal?: AbortSignal }, + ): Promise { + return await promises.setTimeout(delay, undefined, options); + }, + yield: promises.setImmediate, +}; + export default { setTimeout, clearTimeout, @@ -97,4 +113,5 @@ export default { setImmediate, setUnrefTimeout, clearImmediate, + promises, }; diff --git a/ext/node/polyfills/timers/promises.ts b/ext/node/polyfills/timers/promises.ts index 68bc05942618a5..b2896fe8096642 100644 --- a/ext/node/polyfills/timers/promises.ts +++ b/ext/node/polyfills/timers/promises.ts @@ -1,17 +1,11 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -import { promisify } from "node:util"; import timers from "node:timers"; -export const setTimeout = promisify(timers.setTimeout), - setImmediate = promisify(timers.setImmediate), - setInterval = promisify(timers.setInterval); +export const setTimeout = timers.promises.setTimeout; +export const setImmediate = timers.promises.setImmediate; +export const setInterval = timers.promises.setInterval; -export const scheduler = { - async wait(delay: number, options?: { signal?: AbortSignal }): Promise { - return await setTimeout(delay, undefined, options); - }, - yield: setImmediate, -}; +export const scheduler = timers.promises.scheduler; export default { setTimeout,