Skip to content

Instantly share code, notes, and snippets.

@fritzy
Created February 8, 2016 23:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fritzy/acbf4a22585725223b6a to your computer and use it in GitHub Desktop.
Save fritzy/acbf4a22585725223b6a to your computer and use it in GitHub Desktop.
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