PHP
·
发表于 5年以前
·
阅读量:8391
const delay = ms => new Promise((resolve, reject) => setTimeout(resolve, ms))
const getData = status => new Promise((resolve, reject) => {
status ? resolve('done') : reject('fail')
})
const getRes = async (data) => {
try {
const res = await getData(data)
const timestamp = new Date().getTime()
await delay(1000)
console.log(res, new Date().getTime() - timestamp)
} catch (error) {
console.log(error)
}
}
getRes(true) // 隔了1秒