Created
November 12, 2012 06:49
-
-
Save winton/4057862 to your computer and use it in GitHub Desktop.
Starting point for playing with Promises/when.js
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
| When = require('when') | |
| x = -> | |
| d = When.defer() | |
| #d.resolve('hello') | |
| d.reject('hello') | |
| d.promise | |
| console.log "" | |
| x().then( | |
| (a) -> | |
| console.log("* 1 success(#{a})") | |
| console.log(" raising error") | |
| throw new Error("1 success exception") | |
| (a) -> | |
| console.log("* 1 error(#{a})") | |
| console.log(" raising error") | |
| throw new Error("1 error exception") | |
| ).then( | |
| (a) -> | |
| console.log("* 2 success(#{a})") | |
| (a) -> | |
| console.log("* 2 error(#{a})") | |
| console.log(" raising error") | |
| throw new Error("2 error exception") | |
| ).then( | |
| (a) -> | |
| console.log("* 3 success(#{a})") | |
| ).then( | |
| (a) -> | |
| console.log("* 4 success(#{a})") | |
| (a) -> | |
| console.log("* 4 error(#{a})") | |
| ) | |
| console.log "" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment