Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. function promiser(input) {
  2. if (input === 1) {
  3. return Promise.resolve(input);
  4. }
  5. if (input === 2) {
  6. return Promise.reject(new Error('Rejected'));
  7. }
  8. throw new Error('Broken');
  9. }
  10.  
  11. promiser(1)
  12. .then((input) => {
  13. console.log(`Got input: ${input}`);
  14. return promiser(2);
  15. }).then((input) => {
  16. console.log(`Got input: ${input}`);
  17. return promiser(3);
  18. })
  19. .catch((err) => {
  20. console.log(err.stack);
  21. });
  22.  
  23. /*
  24. Got input: 1
  25. Error: Rejected
  26. at promiser (/Users/fritzy/test.js:7:27)
  27. at /Users/fritzy/test.js:15:12
  28. at process._tickCallback (node.js:382:9)
  29. at Function.Module.runMain (module.js:432:11)
  30. at startup (node.js:141:18)
  31. at node.js:980:3
  32. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement