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

176
Visualizações
How to solve this sequential async task problem in javascript?

In the below code snippet ths tasks are an object of tasks and the function defination should be such a way that the expected output should match.

    Let tasks = {
        ‘a’: {
            job: function(finish){
                setTimeout(() => {
                    console.log(‘A done’)
                    finish();
                }, 5000)
            },
            dependencies: []
        },
        ‘b’: {
            job: function(finish){
                setTimeout(() => {
                    console.log(‘B done’)
                    finish();
                }, 2000)
            },
            dependencies: []
        },
        ‘c’: {
            job: function(finish){
                setTimeout(() => {
                    console.log(‘C done’)
                    finish();
                }, 2000)
            },
            dependencies: [‘a’, ‘b’]
        },
        ‘d’: {
            job: function(finish){
                setTimeout(() => {
                    console.log(‘D done’)
                    finish();
                }, 1000)
            },
            dependencies: []
        },
        ‘e’: {
            job: function(finish){
                setTimeout(() => {
                    console.log(‘E  done’)
                    finish();
                }, 2000)
            },
            dependencies: [‘c’, ‘b’]
        },
    };

// implement a executeTasks function which can be invoked like below

executeTasks(tasks, function(){
    console.log(‘all done’);
})


function executeTasks(taskList, callback) {
    // write your code here
}

// Expected output

D done
B done
A done
C done
E done
All done

the function executeTasks will take a tasklist as shown example on the top and also a callback. The nature of the function is that the tasks will be executed with considering all the dependencies and once all tasks are executed the passed callback should invoke. The expected output is an example how the result will be for that given task list.

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

0

Use rxjs, forkJoin might help you do it gracefully. https://rxjs.dev/api/index/function/forkJoin

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