add src folder

This commit is contained in:
PAlexanderFranklin 2023-08-30 17:31:14 -07:00
parent 15cc89bb00
commit 36dcf02bcc
3 changed files with 10 additions and 10 deletions

View File

@ -6,7 +6,7 @@
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1", "test": "echo \"Error: no test specified\" && exit 1",
"start": "node index.js" "start": "node ./src/index.js"
}, },
"author": "", "author": "",
"license": "MIT", "license": "MIT",

View File

@ -1,18 +1,10 @@
import puppeteer from "puppeteer-core" import puppeteer from "puppeteer-core"
import * as utils from "./utils.js"
function sleep(ms) { function sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, 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() { async function main() {
const browser = await puppeteer.launch({ const browser = await puppeteer.launch({
headless: false, headless: false,

8
src/utils.js Normal file
View File

@ -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)
}