Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

1.3K
Visualizações
cluster module to interact with child processes (workers)

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.
  • Your function should return a Promise object that resolves to an array of results.
  • The calculations should run in parallel.
  • The order between the inputs and outputs should be preserved.
// 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)
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda