Advertisement
ReutenkoIvan

Promise

Jul 29th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // let val = 'foo';
  2.  
  3. // setTimeout(
  4. //   function timeout() {
  5. //     console.log(val, 'setTimeout');
  6. //     val = 'bar';
  7. //   }, 0);
  8.  
  9. // const p = new Promise((res, rej) => {
  10. //   console.log(val, 'Promise body');
  11. //   val = 'baz';
  12. //   res(val);
  13. // });
  14.  
  15. // p.then(res => console.log(val, 'Promis then') );
  16.  
  17. // console.log(val, 'sequential code');
  18. // val = 'foo';
  19.  
  20. //=======================================================================
  21.  
  22. // function job(state) {
  23. //     return new Promise(function(resolve, reject) {
  24. //         if (state) {
  25. //             resolve('success');
  26. //         } else {
  27. //             reject('error');
  28. //         }
  29. //     });
  30. // }
  31.  
  32. // let promise = job(true);
  33.  
  34. // promise
  35. // .then(function(data) {
  36. //     console.log(data);
  37.  
  38. //     return job(true);
  39. // })
  40.  
  41. // .then(function(data) {
  42. //     if (data !== 'victory') {
  43. //         throw 'Defeat';
  44. //     }
  45.  
  46. //     return job(true);
  47. // })
  48.  
  49. // .then(function(data) {
  50. //     console.log(data);
  51. // })
  52.  
  53. // .catch(function(error) {
  54. //     console.log(error);
  55.  
  56. //     return job(false);
  57. // })
  58.  
  59. // .then(function(data) {
  60. //     console.log(data);
  61.  
  62. //     return job(true);
  63. // })
  64.  
  65. // .catch(function(error) {
  66. //     console.log(error);
  67.  
  68. //     return 'Error caught';
  69. // })
  70.  
  71. // .then(function(data) {
  72. //     console.log(data);
  73.  
  74. //     return new Error('test');
  75. // })
  76.  
  77. // .then(function(data) {
  78. //     console.log('Success:', data.message);
  79. // })
  80.  
  81. // .catch(function(data) {
  82. //     console.log('Error:', data.message);
  83. // });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement