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

147
Visualizações
How to run function in different thread with node.js

I have a REST API coded with Node.js and there is one route that applies NTFS Rights to folders. The request can take 1 second but can also last several minutes (it depends on the size of the folder).

To summarize, if the rights take less than 5 seconds to be applied, I want to return the status code 200.

If the rights have not finished being applied, I would like to return the status code 202.

For that I use Promise.race:

return Promise.race([applyRights(), sleep(5)]
    .then(result => {
        statusCode = 200;
        if (result === undefined) {
            statusCode = 202;
         }
    });

My problem is that the function applyRights performs quite complex operations. Including writes to the Windows File System and applying NTFS rights with a C++ library.

It's look like the C++ function to applies NTFS rights is blocking the event loop. That means that my function sleep is only executed after applyRights is done.

Is there an easy way to run the C++ function in another thread or something like this to let the job continue in background without blocking the event loop ?

Or do I need to update the C++ library ? (what I would like to avoid doing)

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