SOURCE

function generateToAsync(generator) {
    return function (...args) {
        const gen = generator(...args)
        return new Promise((resolve, reject) => {
            function request(key, arg) {
                let res = null
                try {
                    res = gen[key](arg)
                } catch (e) {
                    reject(e)
                }
                const { value, done } = res
                if (done) {
                    return resolve(value)
                } else {
                    Promise.resolve(value).then((val) => {
                        request('next', val)
                    }, (e) => {
                        request('throw', err)
                    })
                }
                request('next')
            }
        })
    }
}

async function a() {
    await 1
    console.log(1)
}
async function b() {
    new Promise((resolve, reject) => {
        console.log("b")
        resolve(22)
    }).then((val) => {
        console.log('val', val)
    })
}
a()
b()
console 命令行工具 X clear

                    
>
console