mirror of
https://github.com/denoland/deno.git
synced 2025-08-27 14:04:54 +00:00
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:
parent
0ffcb46e0f
commit
616354e76c
35 changed files with 952 additions and 1020 deletions
|
@ -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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue