I need to execute a function A and B in parallel, both functions have no dependency with each other.
I could use some Promise framework, however, I would like to learn how to do it with using Node.js async/await only.
My understanding it's both functions A and B start almost in parallel due to the async and await instructions.
So to ensure a delay on function A I inserted a 4 seconds synchronous delay in function A.
async function loop() {
const process = require('child_process');
async function A() {
process.execSync("sleep 4");
console.log("A");
}
async function B() {
console.log("B");
}
await A()
await B()
};
loop();
I expected to see on screen "B" and after 4 seconds, "A".
However, I seeing nothing for 4 seconds and after "A" and "B".