Options
All
  • Public
  • Public/Protected
  • All
Menu

External module @tomato-js/async

Index

Functions

callbackify

  • callbackify(fn: Function): (Anonymous function)
  • promise函数回调化

    新增于v0.0.14

    脚本举例

      import { callbackify } from '@tomato-js/async'
      const fixture = () => {
        return new Promise((resolve, reject) => {
          resolve("brizer");
        });
      };
      callbackify(fixture)((err,value)=>value);//brizer

    Parameters

    • fn: Function

      promise函数

    Returns (Anonymous function)

    callback风格函数

pIf

  • pIf<ValueType, DoIfRetureType, DoElseReturnType>(condition: boolean | ((value: ValueType) => boolean | PromiseLike<boolean>), doIf: (value: ValueType) => DoIfRetureType | PromiseLike<DoElseReturnType>, doElse?: undefined | ((value: ValueType) => DoElseReturnType | PromiseLike<DoElseReturnType>)): (Anonymous function)
  • 有条件的promise链

    新增于v0.0.15

    脚本举例

      import { pIf } from '@tomato-js/async'
      Promise.resolve([]).then(pIf(condition(), () => "if",()=>"else")).then;
      Promise.resolve([]).then(pIf(true, () => "if").then();

    Type parameters

    • ValueType

    • DoIfRetureType

    • DoElseReturnType

    Parameters

    • condition: boolean | ((value: ValueType) => boolean | PromiseLike<boolean>)

      判断条件

    • doIf: (value: ValueType) => DoIfRetureType | PromiseLike<DoElseReturnType>

      true时后续逻辑函数

        • (value: ValueType): DoIfRetureType | PromiseLike<DoElseReturnType>
        • Parameters

          • value: ValueType

          Returns DoIfRetureType | PromiseLike<DoElseReturnType>

    • Optional doElse: undefined | ((value: ValueType) => DoElseReturnType | PromiseLike<DoElseReturnType>)

      false时后续逻辑函数

    Returns (Anonymous function)

    promise

pLog

  • pLog<ValueType>(logger?: (message?: any, ...optionalParams: any[]) => void): (Anonymous function)
  • promise链参数透传

    新增于v0.0.15

    脚本举例

      import { pLog } from '@tomato-js/async'
      Promise.resolve('tomato')
          .then(pLog()) // Logs `tomato`
          .then(value => {
              // `value` is still `tomato`
          });

    Type parameters

    • ValueType

    Parameters

    • Default value logger: (message?: any, ...optionalParams: any[]) => void = console.log
        • (message?: any, ...optionalParams: any[]): void
        • Parameters

          • Optional message: any
          • Rest ...optionalParams: any[]

          Returns void

    Returns (Anonymous function)

    promise

pTap

  • pTap<ValueType>(fn: (value: ValueType) => unknown): (Anonymous function)
  • promise链参数透传

    新增于v0.0.15

    脚本举例

      import { pTap } from '@tomato-js/async'
      Promise.resolve('tomato')
          .then(pTap(console.log)) // Logs `tomato`
          .then(value => {
              // `value` is still `tomato`
          });

    Type parameters

    • ValueType

    Parameters

    • fn: (value: ValueType) => unknown

      中间函数

        • (value: ValueType): unknown
        • Parameters

          • value: ValueType

          Returns unknown

    Returns (Anonymous function)

    promise

promisify

  • promisify(fn: Function): (Anonymous function)
  • 回调函数promise化

    新增于v0.0.14

    脚本举例

      import { promisify } from '@tomato-js/async'
      promisify(fs.readFile)('package.json').then();

    Parameters

    • fn: Function

      回调style的函数

    Returns (Anonymous function)

    promise风格函数

sleep

  • sleep(ms: number, options?: SleepOptions): Promise<unknown>
  • 延迟

    脚本举例

      import { sleep } from '@tomato-js/async'
      async function sleepyWork() {
        console.log("I'm going to sleep for 1 second.");
        await sleep(1000);
        console.log('I woke up after 1 second.');
      }

    Parameters

    • ms: number

      延迟毫秒数

    • Default value options: SleepOptions = {}

    Returns Promise<unknown>

    延迟Promise

Generated using TypeDoc