Promise with timer and error handling
JavaScript
Medium
promises
Task «Promise with timer and error handling»
Write a function `processWithTimeout` that takes an array of numbers and returns a promise. The promise should resolve with an array where each element is multiplied by 2, if all numbers are positive. If at least one number is negative, the promise should be rejected with the message 'Negative number found'. To simulate asynchrony, use setTimeout with a delay of 1000 ms. Also implement an async function `run` that calls `processWithTimeout` and outputs the result or error to the console.
Input Format
A string containing an array of numbers separated by commas.
Output Format
If the promise is resolved, the string 'Result: [number1, number2, ...]' is displayed. If rejected, 'Error: Negative number found' is displayed.
Examples
Example 1
INPUT
-1,2,3
OUTPUT
Error: Negative number found
Example 2
INPUT
Война и мир
Лев Толстой
1869
OUTPUT
Error: Negative number found
Example 3
INPUT
Мастер и Маргарита
Михаил Булгаков
1966
OUTPUT
Error: Negative number found
main.js