diff --git a/package.json b/package.json index 81d10aa..25562d1 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", - "start": "node index.js" + "start": "node ./src/index.js" }, "author": "", "license": "MIT", diff --git a/index.js b/src/index.js similarity index 86% rename from index.js rename to src/index.js index effc8f1..e3b9f79 100644 --- a/index.js +++ b/src/index.js @@ -1,18 +1,10 @@ import puppeteer from "puppeteer-core" +import * as utils from "./utils.js" function sleep(ms) { return new Promise((resolve) => setTimeout(resolve, ms)) } -const settlePromises = async (promiseArray) => { - const settledArray = await Promise.allSettled(promiseArray) - let errors = settledArray.filter((resolved) => resolved.reason) - if (errors.length) { - throw errors - } - return settledArray.map((resolved) => resolved.value) -} - async function main() { const browser = await puppeteer.launch({ headless: false, diff --git a/src/utils.js b/src/utils.js new file mode 100644 index 0000000..28825ec --- /dev/null +++ b/src/utils.js @@ -0,0 +1,8 @@ +export async function settlePromises(promiseArray) { + const settledArray = await Promise.allSettled(promiseArray) + let errors = settledArray.filter((resolved) => resolved.reason) + if (errors.length) { + throw errors + } + return settledArray.map((resolved) => resolved.value) +}