Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

175
Views
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 answers
Answer question

0

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

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!