Created
June 18, 2013 20:37
-
-
Save jsantell/5809125 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
| 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