I have this piece of code.
function a() {
var promise1 = Promise.resolve(3);
var promise2 = 42;
var promise3 = new Promise(function(resolve, reject) {
setTimeout(resolve, 2000, 'foo');
});
Promise.all([promise1, promise2, promise3]).then(function(values) {
console.log("done", values);
});
}
async function b() {
await a();
}
b();
console.log("here")
Here, we get the output
"here"
and then after two seconds, we get
"done" Array [3, 42, "foo"]
How do I change this code so that inside function b(), we are actually waiting for a() to complete and then continue the execution of the code?
Hence, the output I want is
Wait two seconds and see
"done" Array [3, 42, "foo"]
"here"