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

178
Vistas
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 Respuestas
Responde la pregunta

0

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

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