SOURCE

function wait(n){
    return new Promise((resolve, reject) => {
        setTimeout(() => {
            console.log('resolving...',n)
            resolve(n+1)
        },1000*n)
    })
}

async function test(m){
    try {
        let a = await wait(1)
        console.log('233',a)
        let b = wait(0.1)
        console.log('2336',b)
        // let c = await Promise.all([wait(1),wait(2)])
        // console.log(c)
    } catch (error) {
        console.error(error," error!!")
    }
    
}

async function timer (n) {
    for(let i = 0; i<n ; i++){
        await (function(){
            return new Promise((resolve) => {
                setTimeout(() => {
                    console.log((i+1)+'s has gone..')
                    resolve()
                },1000)
            })
        })()
    }
}

function oldTimer(n){
    for(let i =0; i<n; i++){
        (function(){
            setTimeout(() => {
                console.log((i+1)+'s has gone..',this)
            },(i+1)*1000)
        })()
    }
}

function testTimer(n){
    for(let i =0; i<n; i++){
        setTimeout(() => {
            console.log((i+1)+'s has gone..')
        },0)
    }
}

// console.log('1')
// test(1)
// test(3)
// console.log('2')

// wait(1).then(data => {
//     console.log('233', data)
//     wait(data+1).then(data2 => {
//         console.log('233', data2)
//     })
// })

// Promise.race([wait(1),wait(2),wait(4)]).then((data) => {
//     console.log('finally resolved.',data)
// }).catch(error => {
//     console.log(error)
// })

// timer(10)
testTimer(10)
console 命令行工具 X clear

                    
>
console