SOURCE

function generatePromiseFunc(index) {
    return function () {
        return new Promise((resolve, reject) => {
            setTimeout(() => {
                console.log(index)
                resolve(index)
            }, 1000)
        })
    }
}

const list = []

for(let i = 0; i < 10; i++) {
    list.push(generatePromiseFunc(i))
}


// 方法一: 递归调用
function promise_queue(list, index) {
    if (index >= 0 && index < list.length) {
        list[index]().then(() => {
            promise_queue(list, index + 1)
        })
    }
}
// promise_queue(list, 0)

// 方法二: reduce
list.reduce((pro, next)=>pro.then(next), Promise.resolve())
console 命令行工具 X clear

                    
>
console