Skip to content

Instantly share code, notes, and snippets.

@humphd
Created October 6, 2020 23:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save humphd/f146e96581269a9002cc4b9a52ec3f4b to your computer and use it in GitHub Desktop.
Save humphd/f146e96581269a9002cc4b9a52ec3f4b to your computer and use it in GitHub Desktop.
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