Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ext/node): export 'promises' symbol from 'node:timers' #25589

Merged
merged 3 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions ext/node/polyfills/timers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
return await promises.setTimeout(delay, undefined, options);
},
yield: promises.setImmediate,
};

export default {
setTimeout,
clearTimeout,
Expand All @@ -97,4 +113,5 @@ export default {
setImmediate,
setUnrefTimeout,
clearImmediate,
promises,
};
14 changes: 4 additions & 10 deletions ext/node/polyfills/timers/promises.ts
Original file line number Diff line number Diff line change
@@ -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<void> {
return await setTimeout(delay, undefined, options);
},
yield: setImmediate,
};
export const scheduler = timers.promises.scheduler;

export default {
setTimeout,
Expand Down