refactor: replace deferred() from std/async with Promise.withResolvers() (#21234)

Closes #21041

---------

Signed-off-by: Asher Gomez <ashersaupingomez@gmail.com>
This commit is contained in:
Asher Gomez 2023-11-22 22:11:20 +11:00 committed by GitHub
parent 0ffcb46e0f
commit 616354e76c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
35 changed files with 952 additions and 1020 deletions

View file

@ -4,7 +4,6 @@ import {
assert,
assertEquals,
} from "../../../test_util/std/testing/asserts.ts";
import { deferred } from "../../../test_util/std/async/deferred.ts";
Deno.test(async function foo() {
const asyncLocalStorage = new AsyncLocalStorage();
@ -68,16 +67,16 @@ Deno.test(async function bar() {
Deno.test(async function nested() {
const als = new AsyncLocalStorage();
const promise = deferred();
const promise1 = deferred();
const deferred = Promise.withResolvers();
const deferred1 = Promise.withResolvers();
als.run(null, () => {
als.run({ x: 1 }, () => {
promise.resolve(als.getStore());
deferred.resolve(als.getStore());
});
promise1.resolve(als.getStore());
deferred1.resolve(als.getStore());
});
assertEquals(await promise, { x: 1 });
assertEquals(await promise1, null);
assertEquals(await deferred.promise, { x: 1 });
assertEquals(await deferred1.promise, null);
});