Skip to content

Instantly share code, notes, and snippets.

@patarkf
Last active June 10, 2017 20:11
Show Gist options
  • Save patarkf/300715c6cf9216251ef6d90a2feaaedd to your computer and use it in GitHub Desktop.
Save patarkf/300715c6cf9216251ef6d90a2feaaedd to your computer and use it in GitHub Desktop.
let promise = Promise.resolve();
const posts = [{}, {}, {}];
posts.forEach(post => {
promise = promise.then(() => {
return db.insert(post);
});
});
promise.then(() => {
// now all our docs have been saved
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment