<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<script>
// function yao() {
// return new Promise((resolve, reject) => {
// let sino = parseInt(Math.random() * 6 + 1)
// setTimeout(() => {
// resolve(sino)
// }, 3000)
// })
// }
function eat() {
console.log('吃');
}
function he() {
console.log('喝');
}
function sleep() {
console.log('睡');
}
async function test() {
await setTimeout(sleep, 3000);
await setTimeout(eat, 2000);
await setTimeout(he, 1000);
// let n1 = yao();
// console.log(n1);
// let n = await yao();
// console.log(n);
}
test();
console.log('hah');
</script>
</head>
<body></body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
// function print(delay, message) {
// return new Promise(function (resolve, reject) {
// setTimeout(function () {
// console.log(message);
// resolve();
// }, delay);
// });
// }
function print(delay, message) {
setTimeout(function () {
console.log(message);
}, delay)
}
async function asyncFunc() {
// print(1000, "First");
// print(4000, "Second");
// print(3000, "Third");
await print(1000, "First");
await print(4000, "Second");
await print(3000, "Third");
}
asyncFunc();
</script>
</body>
</html>