Last active
July 2, 2018 08:08
-
-
Save puemos/a2b9a9e0ed081449f8cb12debdee1b12 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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