You are developing a task scheduling system where multiple tasks must be executed concurrently. Each task takes a specified amount of time to complete, and the system needs to handle and log messages for both successes and failures.
Write a function executeTask
that accepts two parameters.
taskName
: A string representing the name of the task.
taskDuration
: A number representing the duration of the task in milliseconds.
The executeTask
function should return a promise. The promise should resolve with the message <taskName> completed successfully in <taskDuration> ms. after the specified duration and reject with the message <taskName> failed: Invalid duration. if the provided taskDuration is negative.
Additionally, create a function runScheduler
that accepts an array of tasks. Each task is an object with the following structure:
Use this function to execute all tasks concurrently and log the results as follows.
- If all tasks are successful, log the success messages in the specified order.
- If any task fails, immediately log the error in the format Error:, <error> and stop processing further tasks.
Regardless of the task's success or failure, always log the completionMessage
to the console after the task is complete.