Skip to content

parallelCall

Functions

parallelCall()

parallelCall<F>(fns, ...args): ParallelCallReturn<F>

并行执行函数列表并返回所有结果

Type parameters

ParameterValue
F extends AnyFn[][]

Parameters

ParameterTypeDescription
fnsF函数列表
...argsParameters<F[number]>参数列表

Returns

ParallelCallReturn<F>

执行结果列表,存在异步函数时返回 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

ParameterValue
F extends readonly AnyFn[][]