Functions
parallelCall()
parallelCall<
F>(fns, ...args):ParallelCallReturn<F>
并行执行函数列表并返回所有结果
Type Parameters
| Type Parameter | Default type |
|---|---|
F extends Fn[] | [] |
Parameters
| Parameter | Type | Description |
|---|---|---|
fns | F | 函数列表 |
...args | Parameters<F[number]> | 参数列表 |
Returns
执行结果列表,存在异步函数时返回 Promise
Example
ts
const fn1 = () => sleep(3000).then(() => 1)
const fn2 = () => 2
parallelCall([fn1, fn2])
// => Promise { [1, 2] }
const fn1 = () => 1
const fn2 = () => 2
parallelCall([fn1, fn2])
// => [1, 2]Type Aliases
ParallelCallReturn<F>
ParallelCallReturn<
F> ={ -readonly [K in keyof F]: Awaited<ReturnType<F[K]>> }extends infer R ?IfTrue<UnionHas<ReturnType<F[number]>,Promise<any>>,Promise<R>,R> : []
Type Parameters
| Type Parameter | Default type |
|---|---|
F extends readonly Fn[] | [] |