Skip to content

Instantly share code, notes, and snippets.

@puemos
Last active July 2, 2018 08:08
Show Gist options
  • Save puemos/a2b9a9e0ed081449f8cb12debdee1b12 to your computer and use it in GitHub Desktop.
Save puemos/a2b9a9e0ed081449f8cb12debdee1b12 to your computer and use it in GitHub Desktop.
async function publishPipeline(post){
if (!validate(post)){
return { post, status: "failed" };
}
try {
await publish(post)
return { post, status: "published" };
} catch (e) {
return { post, status: "failed", error: e };
}
}
async function publishAll() {
const posts = await getPosts();
const publishTasks = posts.map(publishPipeline);
const results = await Promise.all(publishTasks);
const successes = results.filter(post => post.status === "published");
const failures = results.filter(post => post.status === "failed");
return {
successes,
failures
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment