Advertisement
Guest User

Untitled

a guest
Sep 13th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width">
  6. <title>JS Bin</title>
  7. </head>
  8. <body>
  9.  
  10. <script id="jsbin-javascript">
  11. const func1 = (res) => {
  12. return new Promise ((res,rej) => {
  13. setTimeout(() => {
  14. console.log('1');
  15. res();
  16. }, 500);
  17. });
  18. };
  19.  
  20. const func2 = (res) => {
  21. return new Promise((res,rej) => {
  22. setTimeout(() => {
  23. console.log('2');
  24. res();
  25. }, 100);
  26. });
  27. };
  28.  
  29. const func3 = (res) => {
  30. return new Promise((res,rej) => {
  31. setTimeout(() => {
  32. console.log('3');
  33. res();
  34. }, 250);
  35. });
  36. };
  37.  
  38.  
  39. const promises = [];
  40. const doPassword = true;
  41.  
  42. if ( doPassword ) {
  43. promises.push(func1);
  44. promises.push(func2);
  45. }
  46. promises.push(func3);
  47.  
  48. promises.reduce(function(p, func) {
  49. return p.then(() => func());
  50. }, Promise.resolve(null));
  51. </script>
  52.  
  53.  
  54.  
  55. <script id="jsbin-source-javascript" type="text/javascript">const func1 = (res) => {
  56. return new Promise ((res,rej) => {
  57. setTimeout(() => {
  58. console.log('1');
  59. res();
  60. }, 500);
  61. });
  62. };
  63.  
  64. const func2 = (res) => {
  65. return new Promise((res,rej) => {
  66. setTimeout(() => {
  67. console.log('2');
  68. res();
  69. }, 100);
  70. });
  71. };
  72.  
  73. const func3 = (res) => {
  74. return new Promise((res,rej) => {
  75. setTimeout(() => {
  76. console.log('3');
  77. res();
  78. }, 250);
  79. });
  80. };
  81.  
  82.  
  83. const promises = [];
  84. const doPassword = true;
  85.  
  86. if ( doPassword ) {
  87. promises.push(func1);
  88. promises.push(func2);
  89. }
  90. promises.push(func3);
  91.  
  92. promises.reduce(function(p, func) {
  93. return p.then(() => func());
  94. }, Promise.resolve(null));
  95. </script></body>
  96. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement