I am converting an async.auto flow to async await code. To simplify my question say I have a set of tasks and a list of dependencies of these tasks on each other how can I convert this to async await code. Here is an example I feel which will cover all the cases(correct me if it does not).
Set of tasks - a(), b(), c(), f(), d(resultOfA, resultOfB), e(resultOfB, resultOfC), g(resultOfF, resultOfE) Here to execute d we need values returned from a and b, and to execute e we need those of b and c, for g we need e and f.
Note that I want to complete all the tasks as early as possible
Edit: Adding a sample async auto flow which I need to convert
async.auto({
a: function(callback) {
setTimeout(() => {
let resA = 3;
callback(null, resA);
}, 1000);
},
b: function(callback) {
setTimeout(() => {
let resB = 4;
callback(null, resB);
}, 1000);
},
c: function(callback) {
setTimeout(() => {
let resC = 5;
callback(null, resC);
}, 1000);
},
d: ['a', 'b', function(results, callback) {
setTimeout(() => {
//following line represents some computations which depends on resA and resB
resD = results.a + results.b;
callback(null, resD);
}, 1000);
}],
e: ['b', 'c', function(results, callback) {
setTimeout(() => {
resE = results.b + results.c;
callback(null, resE);
}, 1000);
}],
f: function(callback) {
callback(null, resF);
},
g: ['e', 'f', function(results, callback) {
setTimeout(() => {
resG = results.e + results.f;
callback(null, resG);
}, 1000);
}]
}, function(err, results) {
if (err) {
console.log('err : ', err);
}
console.log('results : ', results);
});
I am aware of how to run tasks in parallel and in series from these three questions -