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

@ -1,5 +1,4 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
import { deferred } from "../test_util/std/async/deferred.ts";
import {
dirname,
fromFileUrl,
@ -182,10 +181,10 @@ const downloadUrl =
export async function downloadPrebuilt(toolName) {
// Ensure only one download per tool happens at a time
if (DOWNLOAD_TASKS[toolName]) {
return await DOWNLOAD_TASKS[toolName];
return await DOWNLOAD_TASKS[toolName].promise;
}
const downloadPromise = DOWNLOAD_TASKS[toolName] = deferred();
const downloadDeferred = DOWNLOAD_TASKS[toolName] = Promise.withResolvers();
const spinner = wait({
text: "Downloading prebuilt tool: " + toolName,
interval: 1000,
@ -230,12 +229,12 @@ export async function downloadPrebuilt(toolName) {
await Deno.rename(tempFile, toolPath);
} catch (e) {
spinner.fail();
downloadPromise.reject(e);
downloadDeferred.reject(e);
throw e;
}
spinner.succeed();
downloadPromise.resolve(null);
downloadDeferred.resolve(null);
}
export async function verifyVersion(toolName, toolPath) {