console
let str2 = "";
let str = "";
function testAwait() {
return new Promise((resolve) => {
setTimeout(function () {
console.log("testAwait");
resolve(str);
}, 3000);
}).then(res => {
str = "我是变量1"
})
}
function testAwait2() {
return new Promise((resolve) => {
setTimeout(function () {
console.log("testAwait2");
resolve();
}, 1000);
}).then(res => {
str2 = str
console.log(str2)
})
}
async function helloAsync() {
await testAwait();
await testAwait2();
console.log("helloAsync");
hello()
}
function hello() {
console.log("nihao")
}
helloAsync();
let str2 = "";
let str = "";
function testAwait() {
return new Promise((resolve) => {
setTimeout(function () {
console.log("testAwait");
resolve(str);
}, 3000);
}).then(res => {
str = "我是变量1"
})
}
function testAwait2() {
return new Promise((resolve) => {
setTimeout(function () {
console.log("testAwait2");
resolve();
}, 1000);
}).then(res => {
str2 = str
console.log(str2)
})
}
async function helloAsync() {
await testAwait();
await testAwait2();
console.log("helloAsync");
hello()
}
function hello() {
console.log("nihao")
}
helloAsync();