Please help In this exercise, you will use the cluster module to interact with child processes (workers).
A worker has been implemented at workerPath. It uses CPU-heavy computing logic. The worker is waiting for the input message from the primary cluster process. It then calculates the result, returns it, and exits.
Your goal is to implement the asynchronous function doCalculations(inputs, workerPath) that sends inputs to the worker and returns the calculation results.
inputs is a list containing the string input(s) to be sent.workerPath is a string representing the path to the worker file.// JavaScript code below
const cluster = require("cluster");
/**
*
* @param {string[]} inputs
* @param {string} workerPath
* @returns {Promise<Array<string | number>} calculation results returned from workers
*/
async function doCalculations(inputs, workerPath = "/tmp/deps/worker") {
// Your code goes here
const result = []; // = calculate(inputs)
return result;
}
doCalculations(['hello', 'world']).then(console.log).catch(console.error)