External module @tomato-js/async
Functions
callbackify
- callbackify(fn: Function): (Anonymous function)
-
Parameters
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)
-
Type parameters
-
ValueType
-
DoIfRetureType
-
DoElseReturnType
Parameters
-
condition: boolean | ((value: ValueType) => boolean | PromiseLike<boolean>)
-
doIf: (value: ValueType) => DoIfRetureType | PromiseLike<DoElseReturnType>
-
- (value: ValueType): DoIfRetureType | PromiseLike<DoElseReturnType>
-
Parameters
Returns DoIfRetureType | PromiseLike<DoElseReturnType>
-
Optional doElse: undefined | ((value: ValueType) => DoElseReturnType | PromiseLike<DoElseReturnType>)
Returns (Anonymous function)
promise
pLog
- pLog<ValueType>(logger?: (message?: any, ...optionalParams: any[]) => void): (Anonymous function)
-
Type parameters
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)
-
Type parameters
Parameters
-
fn: (value: ValueType) => unknown
-
- (value: ValueType): unknown
-
Parameters
Returns unknown
Returns (Anonymous function)
promise
promisify
- promisify(fn: Function): (Anonymous function)
-
Parameters
Returns (Anonymous function)
promise风格函数
sleep
- sleep(ms: number, options?: SleepOptions): Promise<unknown>
-
Parameters
-
ms: number
-
Default value options: SleepOptions = {}
Returns Promise<unknown>
延迟Promise
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