1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
| function requestData(url) { console.log("request data") return new Promise((resolve) => { setTimeout(() => { resolve(url) }, 3000) }) }
async function test() { console.log("test function") return "test" }
async function bar() { console.log("bar function")
return new Promise((resolve) => { setTimeout(() => { resolve("bar") }, 2000); }) }
async function demo() { console.log("demo function") return { then: function(resolve) { resolve("demo") } } }
async function foo() { console.log("foo function")
const res1 = await requestData("why") console.log("res1:", res1)
const res2 = await test() console.log("res2:", res2)
const res3 = await bar() console.log("res3:", res3)
const res4 = await demo() console.log("res4:", res4) }
foo()
|