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

231
Visualizações
Nested Threads For Nested Functions?

I currently using async/await method and that's helpful with https requests but doesn't help with synchronous code.

What can I do to improve performance in that case?

Can I use something like nested worker threads?

I can use worker threads in the last functions but I want to be able to use them in nested mode!

Is it possible to do something like that in javascript/node.js or I have to switch language/platform!?

Code example:

(async(){
    /*Some code*/
    let Items=[]; //Long array
    for(let Item in Items){
        (async(){
            /*Some code*/
            let Items=[]; //Long array
            for(let Item in Items){
                (async(){
                    //And so on ...
                })();
            }
            /*Wait until all functions done*/
            /*Some code*/
        })();
    }
    /*Wait until all functions done*/
    /*Some code*/
})();

Best answer until now: Using shared resources between threads, Because threads can't run in nested mode (making a tree/within each other)!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Yes, code can use something like Node.js Worker threads to allow parallelism for CPU-bound work.

Workers (threads) are useful for performing CPU-intensive JavaScript operations. They do not help much with I/O-intensive work. The Node.js built-in asynchronous I/O operations are more efficient than Workers can be.

The async concurrency model is still used and each execution context is single-threaded.

The worker threads are themselves running in separate execution contexts and, conceptually in context of await (eg. of promise wrappers around the events), using worker threads is little different than using XHR to dispatch processing to remote compute servers.

Unlike more direct multithreaded support in other languages, this also comes with the restriction that objects are not implicitly shared between the node app and any worker threads, as they are not shared in remote XHR work. Code will need to be written to appropriately divide data and join results or otherwise marshal through a shared resource (eg. filesystem or SharedArrayBuffer).

about 4 years ago · Juan Pablo Isaza Relatório
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