Skip to content

Instantly share code, notes, and snippets.

@humphd
Created Oct 6, 2020
Embed
What would you like to do?
Promise example
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