数组map实现

function fn1() {
    return new Promise((resolve, reject) => {
        setTimeout(() => {
            console.log(1);
            resolve();
        }, 500)
    })
}

function fn2() {
    return new Promise((resolve, reject) => {
        setTimeout(() => {
            console.log(2);
            resolve();
        }, 500)
    })
}

const arr = [fn1, fn2];

function queue(arr) {
    let promise = Promise.resolve();

    arr.map(fn => {
        promise = promise.then(() => {
            return fn();
        })
    })
}

queue(arr);
分类: JavaScript 标签: promise队列

评论

暂无评论数据

暂无评论数据

目录