From b54065b5daab58d20369d20df064a12d49d42339 Mon Sep 17 00:00:00 2001 From: Vallie Joseph Date: Wed, 20 Dec 2023 21:15:04 +0000 Subject: [PATCH] making a promise array --- .../internal/download/download-artifact.ts | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/packages/artifact/src/internal/download/download-artifact.ts b/packages/artifact/src/internal/download/download-artifact.ts index 2caa92ab..62d6f648 100644 --- a/packages/artifact/src/internal/download/download-artifact.ts +++ b/packages/artifact/src/internal/download/download-artifact.ts @@ -39,19 +39,29 @@ async function exists(path: string): Promise { async function streamExtract(url: string, directory: string): Promise { let retryCount = 0 + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const promises: Promise[] = [] while (retryCount < 5) { - try { - await streamExtractInternal(url, directory) - return - } catch (error) { - retryCount++ - core.warning(`Failed to download artifact. Retrying in 5 seconds...`) - // wait 5 seconds before retrying - await new Promise(resolve => setTimeout(resolve, 5000)) - } + const promise = new Promise(async () => { + try { + await streamExtractInternal(url, directory) + } catch (err) { + retryCount++ + core.warning(`Failed to download artifact. Retrying in 5 seconds...`) + await new Promise(resolve => setTimeout(resolve, 5000)) + } + }) + promises.push(promise) } - throw new Error(`Artifact download failed after ${retryCount} retries.`) + try { + await Promise.all(promises) + core.info('All Promises Returned') + } catch (error) { + throw new Error(`Artifact download failed after ${retryCount} retries.`) + } + + // throw new Error(`Artifact download failed after ${retryCount} retries.`) } async function streamExtractInternal(