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); +} + + +