Advertisement
Guest User

Untitled

a guest
Feb 10th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1.  
  2. var thinkForXMin = function(time, out){
  3. return new Promise(
  4. function(t, c){
  5. setTimeout(function(){
  6. t(out);
  7. }, time);
  8. }
  9. );
  10. };
  11.  
  12. var checkLot = function(t){
  13. setTimeout(function(){
  14. //c("I LOST");
  15. t( Promise.reject("I lost big time. :-(") );
  16. }, 1000);
  17. };
  18. var aaron = function(result){
  19. console.log( "Aaron Message: " + result );
  20. return "Aaron going back to work.";
  21. };
  22. var larry = function(result){
  23. console.log( "Larry Message: " + result );
  24. return thinkForXMin(1000, "I only want to buy if you lose.");
  25. };
  26. var whatWouldHeDo = function(result){
  27. console.log( "He did this. Message: " + result );
  28. };
  29. var catchEverything = function(result){
  30. console.log( "1) WTF is this? " + result );
  31. return "1) Stop playing the lottery.";
  32. };
  33. var catchEverything2 = function(result){
  34. console.log( "2) WTF is this? " + result );
  35. return "2) Stop playing the lottery.";
  36. };
  37. var p = new Promise(checkLot);
  38. p.catch(larry);
  39. p.then(aaronm).then(whatWouldHeDo).catch(catchEverything);
  40. p.catch(catchEverything2).then(larry).then(whatWouldHeDo);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement