js休眠程序,延时程序,可以延时请求
<script>
sleep1 = (time = 1000) => {
return new Promise((resolve) => {
setTimeout(() => {
resolve()
}, time)
})
}
sleep2 = (time = 1000) => {
return new Promise((resolve) => {
setTimeout(() => {
resolve()
}, time)
})
}
fn = async () => {
console.log('111');
await sleep1(2000)
console.log('222');
await sleep2(2000)
console.log('333');
}
fn()
</script>