Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 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. // Complete TaskManager Class to pass tests
  12.  
  13. // List of "tasks" to execute, includes invalid tasks
  14. 'use strict';
  15.  
  16. var TASKS_POOL = ['new Error("wrong item in tasks pool")', function (resolve) {
  17. setTimeout(function () {
  18. resolve(1);
  19. }, 0);
  20. }, function (resolve) {
  21. setTimeout(function () {
  22. resolve(2);
  23. }, 100);
  24. }, null, function () {
  25. return 3;
  26. }];
  27.  
  28. // Class Task Manager
  29. function TaskManager(tasks) {
  30. this.tasks = tasks;
  31. /* your code */
  32. }
  33.  
  34. // Method to execute all tasks asynchronously
  35. TaskManager.prototype.async = function (logger) {/* your code */};
  36.  
  37. // Method to execute all tasks synchronously
  38. TaskManager.prototype.sync = function (logger) {/* your code */};
  39.  
  40. var taskManager = new TaskManager(TASKS_POOL);
  41.  
  42. // Tests
  43. taskManager.sync(function (result) {
  44. console.log('Sync test is %s', result === '123' ? 'passed' : 'not passed');
  45. });
  46.  
  47. var taskManager2 = new TaskManager(TASKS_POOL);
  48.  
  49. taskManager2.async(function (result) {
  50. console.log('Async test is %s', result === '312' ? 'passed' : 'not passed');
  51. });
  52. </script>
  53.  
  54.  
  55.  
  56. <script id="jsbin-source-javascript" type="text/javascript">// Complete TaskManager Class to pass tests
  57.  
  58. // List of "tasks" to execute, includes invalid tasks
  59. const TASKS_POOL = [
  60. 'new Error("wrong item in tasks pool")',
  61. function(resolve) {
  62. setTimeout(function() {
  63. resolve(1);
  64. }, 0);
  65. },
  66. function(resolve) {
  67. setTimeout(function() {
  68. resolve(2);
  69. }, 100);
  70. },
  71. null,
  72. function() {
  73. return 3;
  74. }
  75. ];
  76.  
  77. // Class Task Manager
  78. function TaskManager(tasks) {
  79. this.tasks = tasks;
  80. /* your code */
  81. }
  82.  
  83. // Method to execute all tasks asynchronously
  84. TaskManager.prototype.async = function(logger) {/* your code */};
  85.  
  86. // Method to execute all tasks synchronously
  87. TaskManager.prototype.sync = function(logger) {/* your code */};
  88.  
  89. const taskManager = new TaskManager(TASKS_POOL);
  90.  
  91. // Tests
  92. taskManager.sync(function(result) {
  93. console.log('Sync test is %s', result === '123' ? 'passed' : 'not passed');
  94. });
  95.  
  96. const taskManager2 = new TaskManager(TASKS_POOL);
  97.  
  98. taskManager2.async(function(result) {
  99. console.log('Async test is %s', result === '312' ? 'passed' : 'not passed');
  100. });
  101.  
  102. </script></body>
  103. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement