2022-12-07 05:06:15 +08:00
|
|
|
const delay = () => new Promise(resolve => {
|
2022-12-02 04:13:32 +08:00
|
|
|
setTimeout(resolve, 1000)
|
|
|
|
|
})
|
2022-12-07 05:06:15 +08:00
|
|
|
|
|
|
|
|
await [1,2,3,4,5].reduce(
|
|
|
|
|
async (acc, x) => {
|
|
|
|
|
console.log('wait')
|
|
|
|
|
await acc
|
|
|
|
|
await delay()
|
|
|
|
|
console.log('wait finish')
|
|
|
|
|
},
|
|
|
|
|
Promise.resolve(),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2022-12-02 04:13:32 +08:00
|
|
|
await delay
|
|
|
|
|
console.log('x')
|
|
|
|
|
export const x = 1
|
|
|
|
|
*/
|
|
|
|
|
|
2022-12-07 05:06:15 +08:00
|
|
|
/*
|
2022-12-02 04:13:32 +08:00
|
|
|
const p = {then: y => y(3)}
|
|
|
|
|
|
|
|
|
|
async function test() {
|
|
|
|
|
return await p
|
|
|
|
|
}
|
2022-12-07 05:06:15 +08:00
|
|
|
*/
|
2022-12-02 04:13:32 +08:00
|
|
|
|
|
|
|
|
// TODO remove
|
|
|
|
|
//const x = new Promise((resolve, reject) => resolve(10))
|
|
|
|
|
//const x = Promise.reject(10)
|
|
|
|
|
//const x = Promise.resolve(10)
|
|
|
|
|
//console.log('x', x.status)
|
|
|
|
|
//x.catch(e => {
|
|
|
|
|
// console.log('x', x.status)
|
|
|
|
|
//})
|
|
|
|
|
//const x = new Promise((resolve, reject) => setTimeout(() => resolve(10), 1000))
|
|
|
|
|
//console.log('x', x.status)
|
|
|
|
|
//x.then(() => {
|
|
|
|
|
// console.log('x', x.status)
|
|
|
|
|
//})
|
2022-12-07 05:06:15 +08:00
|
|
|
//console.log(await test())
|