mirror of
https://github.com/denoland/deno.git
synced 2024-11-28 16:20:57 -05:00
feat(ext/node): export 'promises' symbol from 'node:timers' (#25589)
This commit is contained in:
parent
e2875aee74
commit
71d5d47ca9
2 changed files with 21 additions and 10 deletions
|
@ -89,6 +89,22 @@ export function clearImmediate(immediate: Immediate) {
|
||||||
clearTimeout_(immediate._immediateId);
|
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 {
|
export default {
|
||||||
setTimeout,
|
setTimeout,
|
||||||
clearTimeout,
|
clearTimeout,
|
||||||
|
@ -97,4 +113,5 @@ export default {
|
||||||
setImmediate,
|
setImmediate,
|
||||||
setUnrefTimeout,
|
setUnrefTimeout,
|
||||||
clearImmediate,
|
clearImmediate,
|
||||||
|
promises,
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,17 +1,11 @@
|
||||||
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
||||||
import { promisify } from "node:util";
|
|
||||||
import timers from "node:timers";
|
import timers from "node:timers";
|
||||||
|
|
||||||
export const setTimeout = promisify(timers.setTimeout),
|
export const setTimeout = timers.promises.setTimeout;
|
||||||
setImmediate = promisify(timers.setImmediate),
|
export const setImmediate = timers.promises.setImmediate;
|
||||||
setInterval = promisify(timers.setInterval);
|
export const setInterval = timers.promises.setInterval;
|
||||||
|
|
||||||
export const scheduler = {
|
export const scheduler = timers.promises.scheduler;
|
||||||
async wait(delay: number, options?: { signal?: AbortSignal }): Promise<void> {
|
|
||||||
return await setTimeout(delay, undefined, options);
|
|
||||||
},
|
|
||||||
yield: setImmediate,
|
|
||||||
};
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
setTimeout,
|
setTimeout,
|
||||||
|
|
Loading…
Reference in a new issue