console
function timeout(time, str) {
return new Promise((resolve) => {
setTimeout(() => {
console.log('run end:', str);
resolve(str)
}, time * 1000)
});
}
async function main() {
console.log('serial start')
let strArr = ['a', 'b', 'c', 'd', 'e', 'f'];
console.log('serial end');
console.log('parrelel start');
const promiseArr = [
timeout(1, '111'),
timeout(2, '222'),
timeout(3, '333'),
timeout(1, '444'),
timeout(2, '555')
];
const res = await Promise.all(promiseArr);
console.log(res, 'parrelel end');
}
main();
<h1>await 测试代码</h1>