Skip to content

Instantly share code, notes, and snippets.

@jsantell
Created June 18, 2013 20:37
Show Gist options
  • Select an option

  • Save jsantell/5809125 to your computer and use it in GitHub Desktop.

Select an option

Save jsantell/5809125 to your computer and use it in GitHub Desktop.
let bookmarks = [b1, b2, b3];
// Emitter
save(bookmarks).on('data', (bookmark) => {
// a bookmark saved
}).on('end', (bookmarks) => {
// all bookmarks finished
});
// Promise with one input
// Can easily handle errors
save(bookmark)
.then(doSomething, console.error)
.then(doSomethingElse);
// Promise with multi input
// Returns an array of promises? Can handle errors single-y, but always overhead
save(bookmarks).map(p => p.then(doSomething, console.error).then(doSometingElse));
// Returns a promise for the completion of all tasks
// What happens if one save task fails? Promise represents a single computation, and exposing
// only an aggregate seems harder to handle errors, although easier to consume
save(bookmarks).then(bookmarks => bookmarks.map(doSomething))
.then(bookmarks => bookmarks.map(doSomethingElse));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment