Created
November 26, 2015 23:33
-
-
Save himn1/f2039979423bd45921ed to your computer and use it in GitHub Desktop.
JS/CoffeeScript Promises
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
| dict = {a: 1, b: 2, c: 3, d: 4, e: 5} | |
| pro = Promise.resolve() | |
| for k, v of dict | |
| func = (k) -> | |
| pro = pro.then -> | |
| return new Promise (res, rej) -> | |
| if dict[k] is 4 | |
| rej 'fourrrr!!!!' | |
| return | |
| console.log dict[k] | |
| res() | |
| func k | |
| pro.catch (e) -> console.log "error: #{e}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment