<!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>
// async/await
// async 异步
// await 等待
// async 关键字
// 书写在函数function的前面 ,用来修饰函数
// 目的:通过async 修饰的函数 可以在该函数内 使用 await关键字
// await 关键字
// await后面一般跟上promise对象 (所有异步都可以用await修饰)
// await修饰的这个promise 变为一个表达式
// await在函数中后续的代码都会变成同步执行
async function fn() {
console.log(1)
await new Promise(res => {
setTimeout(() => {
res(222)
}, 1000)
}).then(r => console.log(r))
await new Promise(() => { })
console.log('000')
await new Promise(res => {
setTimeout(() => {
res(333)
}, 1000)
}).then(r => console.log(r))
console.log('001')
}
fn()
</script>
</body>
</html>