Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width">
- <title>JS Bin</title>
- </head>
- <body>
- <script id="jsbin-javascript">
- // Complete TaskManager Class to pass tests
- // List of "tasks" to execute, includes invalid tasks
- 'use strict';
- var TASKS_POOL = ['new Error("wrong item in tasks pool")', function (resolve) {
- setTimeout(function () {
- resolve(1);
- }, 0);
- }, function (resolve) {
- setTimeout(function () {
- resolve(2);
- }, 100);
- }, null, function () {
- return 3;
- }];
- // Class Task Manager
- function TaskManager(tasks) {
- this.tasks = tasks;
- /* your code */
- }
- // Method to execute all tasks asynchronously
- TaskManager.prototype.async = function (logger) {/* your code */};
- // Method to execute all tasks synchronously
- TaskManager.prototype.sync = function (logger) {/* your code */};
- var taskManager = new TaskManager(TASKS_POOL);
- // Tests
- taskManager.sync(function (result) {
- console.log('Sync test is %s', result === '123' ? 'passed' : 'not passed');
- });
- var taskManager2 = new TaskManager(TASKS_POOL);
- taskManager2.async(function (result) {
- console.log('Async test is %s', result === '312' ? 'passed' : 'not passed');
- });
- </script>
- <script id="jsbin-source-javascript" type="text/javascript">// Complete TaskManager Class to pass tests
- // List of "tasks" to execute, includes invalid tasks
- const TASKS_POOL = [
- 'new Error("wrong item in tasks pool")',
- function(resolve) {
- setTimeout(function() {
- resolve(1);
- }, 0);
- },
- function(resolve) {
- setTimeout(function() {
- resolve(2);
- }, 100);
- },
- null,
- function() {
- return 3;
- }
- ];
- // Class Task Manager
- function TaskManager(tasks) {
- this.tasks = tasks;
- /* your code */
- }
- // Method to execute all tasks asynchronously
- TaskManager.prototype.async = function(logger) {/* your code */};
- // Method to execute all tasks synchronously
- TaskManager.prototype.sync = function(logger) {/* your code */};
- const taskManager = new TaskManager(TASKS_POOL);
- // Tests
- taskManager.sync(function(result) {
- console.log('Sync test is %s', result === '123' ? 'passed' : 'not passed');
- });
- const taskManager2 = new TaskManager(TASKS_POOL);
- taskManager2.async(function(result) {
- console.log('Async test is %s', result === '312' ? 'passed' : 'not passed');
- });
- </script></body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement