From 44138814693611bbaa0a4acae7a9551448c230fd Mon Sep 17 00:00:00 2001 From: didier amyot Date: Fri, 29 Sep 2023 13:47:18 -0400 Subject: [PATCH] ikds --- src/fast_download.ts | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/fast_download.ts diff --git a/src/fast_download.ts b/src/fast_download.ts new file mode 100644 index 0000000..a68aede --- /dev/null +++ b/src/fast_download.ts @@ -0,0 +1,29 @@ + +import { delay } from "https://deno.land/std@0.202.0/async/delay.ts"; + +function createAllResponses(urls: string[]): Promise[]{ + const ret: Promise[] = []; + for(const url of urls){ + ret.push(fetch(url)); + } + return ret; +} + +function getTextOfAllResponses(responses: Response[]): Promise[]{ + const ret: Promise[] = []; + for(const resp of responses){ + ret.push(resp.text()); + } + return ret; +} + +async function downloadAll(urls: string[]): Promise { + + const promises = createAllResponses(urls); + const responses = await Promise.all(promises); + const textes = getTextOfAllResponses(responses); + return await Promise.all(textes); +} + + +