Created
February 8, 2016 23:49
-
-
Save fritzy/acbf4a22585725223b6a to your computer and use it in GitHub Desktop.
This file contains 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
function promiser(input) { | |
if (input === 1) { | |
return Promise.resolve(input); | |
} | |
if (input === 2) { | |
return Promise.reject(new Error('Rejected')); | |
} | |
throw new Error('Broken'); | |
} | |
promiser(1) | |
.then((input) => { | |
console.log(`Got input: ${input}`); | |
return promiser(2); | |
}).then((input) => { | |
console.log(`Got input: ${input}`); | |
return promiser(3); | |
}) | |
.catch((err) => { | |
console.log(err.stack); | |
}); | |
/* | |
Got input: 1 | |
Error: Rejected | |
at promiser (/Users/fritzy/test.js:7:27) | |
at /Users/fritzy/test.js:15:12 | |
at process._tickCallback (node.js:382:9) | |
at Function.Module.runMain (module.js:432:11) | |
at startup (node.js:141:18) | |
at node.js:980:3 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment