Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

145
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda