<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
function getItem() {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve({
'001': "启动",
'002': "暂停",
'003': "故障",
'004': "重启"
})
}, 2000)
})
}
function getData(item) {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve([
{
id: 1,
status: "001",
title: "这是机器1"
},
{
id: 2,
status: "002",
title: "这是机器2"
},
{
id: 3,
status: "003",
title: "这是机器3"
}
])
},12000)
})
}
async function run() {
console.time()
const [arr1, arr2] = await Promise.all([
getItem(),
getData()
])
// const item = await getItem();
// const data = await getData(item);
arr2.map(i => {
i.status=arr1[i.status]
})
console.log(arr2)
console.timeEnd ()
}
run();
</script>
</body>
</html>
网友评论