• 串行版promise.all,执行完一个才会去执行下一个

    类型参数

    • T

    参数

    • list: ((list: T[]) => Promise<T>)[]

    返回 Promise<T[]>

    let timeStart = Date.now();
    let timeEnd = timeStart;
    let num = 0;
    const list = [
    () => new Promise<number>((res) => {
    setTimeout(() => {
    timeEnd = Date.now();
    num = 200;
    res(200);
    }, 200);
    }),
    () => ((num = 2), Promise.resolve(2)),
    ];
    const res = await syncPromiseAll(list);

    inRange(timeEnd - timeStart, [200, 300]); // true
    res; // [200, 2]
    num; // 2