concurrent.jake.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. namespace('concurrent', function () {
  2. task('A', function () {
  3. console.log('Started A');
  4. return new Promise((resolve, reject) => {
  5. setTimeout(() => {
  6. console.log('Finished A');
  7. resolve();
  8. }, 200);
  9. });
  10. });
  11. task('B', function () {
  12. console.log('Started B');
  13. return new Promise((resolve, reject) => {
  14. setTimeout(() => {
  15. console.log('Finished B');
  16. resolve();
  17. }, 50);
  18. });
  19. });
  20. task('C', function () {
  21. console.log('Started C');
  22. return new Promise((resolve, reject) => {
  23. setTimeout(() => {
  24. console.log('Finished C');
  25. resolve();
  26. }, 100);
  27. });
  28. });
  29. task('D', function () {
  30. console.log('Started D');
  31. return new Promise((resolve, reject) => {
  32. setTimeout(() => {
  33. console.log('Finished D');
  34. resolve();
  35. }, 300);
  36. });
  37. });
  38. task('Ba', ['A'], function () {
  39. console.log('Started Ba');
  40. return new Promise((resolve, reject) => {
  41. setTimeout(() => {
  42. console.log('Finished Ba');
  43. resolve();
  44. }, 50);
  45. });
  46. });
  47. task('Afail', function () {
  48. console.log('Started failing task');
  49. return new Promise((resolve, reject) => {
  50. setTimeout(() => {
  51. console.log('Failing B with error');
  52. throw new Error('I failed');
  53. }, 50);
  54. });
  55. });
  56. task('simple1', ['A','B'], {concurrency: 2}, function () {
  57. return new Promise((resolve, reject) => {
  58. setTimeout(() => {
  59. resolve();
  60. }, 50);
  61. });
  62. });
  63. task('simple2', ['C','D'], {concurrency: 2}, function () {
  64. return new Promise((resolve, reject) => {
  65. setTimeout(() => {
  66. resolve();
  67. }, 50);
  68. });
  69. });
  70. task('seqconcurrent', ['simple1','simple2'], function () {
  71. return new Promise((resolve, reject) => {
  72. setTimeout(() => {
  73. resolve();
  74. }, 50);
  75. });
  76. });
  77. task('concurrentconcurrent', ['simple1','simple2'], {concurrency: 2}, function () {
  78. return new Promise((resolve, reject) => {
  79. setTimeout(() => {
  80. resolve();
  81. }, 50);
  82. });
  83. });
  84. task('subdep', ['A','Ba'], {concurrency: 2}, function () {
  85. return new Promise((resolve, reject) => {
  86. setTimeout(() => {
  87. resolve();
  88. }, 50);
  89. });
  90. });
  91. task('fail', ['A', 'B', 'Afail'], {concurrency: 3}, function () {
  92. return new Promise((resolve, reject) => {
  93. setTimeout(() => {
  94. resolve();
  95. }, 50);
  96. });
  97. });
  98. });