SOURCE

const p = (flag) => {
    return new Promise((resolve, reject) => {
        setTimeout(() => {
            if (flag) {
                resolve(flag)
            } else {
                reject(flag)
            }
        }, 1000)

    })
}

const test = async () => {
    p(true).then((a) => {
        console.log(a)
    })
}

// test()


let loading = false
const load = async (api) => {
    loading = true
    try {
        const data = await api()
        console.log('right')
    } catch (err) {
        console.log('error')
    } finally {
        console.log('finally')
        loading = false
    }
}

load(async () => {
    try {
        await p(true)
        console.log(111)
    } catch {
        console.log(222)
    }


})
console 命令行工具 X clear

                    
>
console