Last active
December 20, 2015 04:59
-
-
Save sheldonh/6075402 to your computer and use it in GitHub Desktop.
waterfall.coffee
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
| waterfall = (i, fs, callback) -> | |
| if fs.length is 0 then callback() | |
| else if fs.length is 1 then fs[0] i, callback | |
| else | |
| p = 0 | |
| scroll = (e, o) -> | |
| if e then callback(e) | |
| else | |
| p += 1 | |
| if p is fs.length - 1 | |
| fs[p](o, callback) | |
| else | |
| fs[p](o, scroll) | |
| fs[p](i, scroll) | |
| waterfall "H", [ | |
| (i, c) -> c(null, i + "e") | |
| (i, c) -> c(null, i + "l") | |
| (i, c) -> c(null, i + "l") | |
| (i, c) -> c(null, i + "o") | |
| ], (e, o) -> console.log "Error:", e, "Output:", r | |
| waterfall "O", [ | |
| (i, c) -> c(null, i + "h") | |
| (i, c) -> c({name: 'Bugger', message: 'Somebody stop me'}, i + "noes") | |
| (i, c) -> console.log "This does not happen"; c(null, i) | |
| ], (e, o) -> console.log "Error:", e, "Output:", r | |
| ### | |
| Error: null Output: Hello | |
| Error: { name: 'Bugger', message: 'Somebody stop me' } Output: undefined | |
| ### |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment