• 一种队列,分支wait和do

    和async、await组合的区别是,lazy支持运行时编程

    返回 {
        do(cb: ((done: Function, value: unknown) => void | Promise<any>)): { do(cb: (done: Function, value: unknown) => void | Promise<any>): ...; wait(ms: number): ...; };
        wait(ms: number): { do(cb: (done: Function, value: unknown) => void | Promise<any>): ...; wait(ms: number): ...; };
    }

    • do:function
      • 参数

        • cb: ((done: Function, value: unknown) => void | Promise<any>)

          回调返回一个值或返回一个promise 供下一个do回调调用

            • (done, value): void | Promise<any>
            • 参数

              • done: Function
              • value: unknown

              返回 void | Promise<any>

        返回 { do(cb: (done: Function, value: unknown) => void | Promise<any>): ...; wait(ms: number): ...; }

    • wait:function
      • 参数

        • ms: number

          等待毫秒数

        返回 { do(cb: (done: Function, value: unknown) => void | Promise<any>): ...; wait(ms: number): ...; }

    lazy()
    .wait(10)
    .do(
    () =>
    new Promise(() => {
    // promise不resolve,那么后面的永远不会执行
    }),
    )
    .wait(20)
    .do((done) => {
    // 普通函数需要调用done才会继续
    done();
    });