Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement