From 616354e76cba0be8af20a0ffefeacfcf6101bafc Mon Sep 17 00:00:00 2001 From: Asher Gomez Date: Wed, 22 Nov 2023 22:11:20 +1100 Subject: refactor: replace `deferred()` from `std/async` with `Promise.withResolvers()` (#21234) Closes #21041 --------- Signed-off-by: Asher Gomez --- ext/node/polyfills/_util/async.ts | 31 +------------------------------ 1 file changed, 1 insertion(+), 30 deletions(-) (limited to 'ext/node/polyfills/_util/async.ts') diff --git a/ext/node/polyfills/_util/async.ts b/ext/node/polyfills/_util/async.ts index a05b670e8..5eeda2a37 100644 --- a/ext/node/polyfills/_util/async.ts +++ b/ext/node/polyfills/_util/async.ts @@ -1,39 +1,10 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -// This module is vendored from std/async/deferred.ts and std/async/delay.ts +// This module is vendored from std/async/delay.ts // (with some modifications) // TODO(petamoriken): enable prefer-primordials for node polyfills // deno-lint-ignore-file prefer-primordials -export interface Deferred extends Promise { - readonly state: "pending" | "fulfilled" | "rejected"; - resolve(value?: T | PromiseLike): void; - // deno-lint-ignore no-explicit-any - reject(reason?: any): void; -} - -/** Creates a Promise with the `reject` and `resolve` functions */ -export function deferred(): Deferred { - let methods; - let state = "pending"; - const promise = new Promise((resolve, reject) => { - methods = { - async resolve(value: T | PromiseLike) { - await value; - state = "fulfilled"; - resolve(value); - }, - // deno-lint-ignore no-explicit-any - reject(reason?: any) { - state = "rejected"; - reject(reason); - }, - }; - }); - Object.defineProperty(promise, "state", { get: () => state }); - return Object.assign(promise, methods) as Deferred; -} - /** Resolve a Promise after a given amount of milliseconds. */ export function delay( ms: number, -- cgit v1.2.3