Skip to content

Instantly share code, notes, and snippets.

@puemos
Last active July 2, 2018 08:11
Show Gist options
  • Save puemos/7031951bc75a7341187a213b4f85b592 to your computer and use it in GitHub Desktop.
Save puemos/7031951bc75a7341187a213b4f85b592 to your computer and use it in GitHub Desktop.
async function publishAll() {
// You get the posts
const posts = await getPosts();
const successes = [];
const failures = [];
for (const post of posts) {
// synchronous check for validtion
if (!validate(post)) {
failures.push({ post, status: "failed" });
} else {
// publish it to the 3rd party api
try {
await publish(post);
results.push({ post, status: "published" });
} catch (e) {
failures.push({ post, status: "failed", error: e });
}
}
}
return {
successes,
failures
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment