Created
October 6, 2020 23:08
-
-
Save humphd/f146e96581269a9002cc4b9a52ec3f4b to your computer and use it in GitHub Desktop.
Promise example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function makeCalls() { | |
return Promise.all( | |
linkArr.map(async link => { | |
try { | |
const response = await fetch(link, { method: "HEAD" }); | |
if (response.status == 200) { // good | |
console.log(`${link} was good! status: ${response.status}`.green); | |
} else if (response.status == 404 || response.status == 401) { // bad | |
console.log(`${link} was bad! status: ${response.status}`.red); | |
allGood = false; | |
} else { // unknown | |
console.log(`${link} was unknown! status: ${response.status}`.gray); | |
} | |
const linkN = link.toString().replace(/(^\w+:|^)\/\//, ''); | |
await dnsPromise(linkN, rrtype) | |
return "Hello from the inner Promise"; | |
} catch(err) { | |
console.log(err); | |
} | |
} | |
).then(data =>{ // for Promise.all | |
console.log(data); | |
resolve(); | |
}).catch(err => { | |
console.log(err); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment