there are two functions
var a = function () {
return new Promise((resolve, reject)=>{
setTimeout(()=>{
resolve("a")
}, 3000)
})
}
var b = function () {
return new Promise((resolve, reject)=>{
setTimeout(()=>{
resolve("b")
}, 2000)
})
}
if executed in this way
;(async()=>{
console.time("test")
var aa = await a()
var bb = await b()
console.log(`$(aa)-${bb}`)
console.timeEnd("test")
})()
the result is
$(aa)-b
test: 5010.7548828125ms //
but if you execute
like this;(async()=>{
console.time("test")
var promiseA = a()
var promiseB = b()
var aa = await promiseA
var bb = await promiseB
console.log(`$(aa)-${bb}`)
console.timeEnd("test")
})()
the result is
$(aa)-b
test: 3001.277099609375ms //
Why is this?