У меня есть несколько функций, таких как следующие
private async p1(): Promise<Result> {
let p1;
// Do stuff.
return p1;
}
private async p5(): Promise<void> {
// Call some external API.
}
Некоторые из них имеют return
, некоторые нет. Но все они делают что-то очень специфичное, и они не зависят друг от друга.
Я пытаюсь вызвать их все асинхронно с Promise.all () и выполнить их параллельно (с быстрым сбоембезопасный). У меня до 15 звонков, например, следующий фрагмент:
let [x1, x2, x3] = await Promise.all([
this.p1,
this.p2,
this.p3,
this.p4,
this.p5,
this.p6,
this.p7,
this.p8,
...
this.p15
]);
Однако меня приветствуют
src/app/view-models/index.ts:69:37 - error TS2345: Argument of type '(Promise<void> | Promise<Result>)[]' is not assignable to parameter of type 'Iterable<void | PromiseLike<void>>'.
Types of property '[Symbol.iterator]' are incompatible.
Type '() => IterableIterator<Promise<void> | Promise<Result>>' is not assignable to type '() => Iterator<void | PromiseLike<void>>'.
Type 'IterableIterator<Promise<void> | Promise<Result>>' is not assignable to type 'Iterator<void | PromiseLike<void>>'.
Types of property 'next' are incompatible.
Type '(value?: any) => IteratorResult<Promise<void> | Promise<Result>>' is not assignable to type '(value?: any) => IteratorResult<void | PromiseLike<void>>'.
Type 'IteratorResult<Promise<void> | Promise<Result>>' is not assignable to type 'IteratorResult<void | PromiseLike<void>>'.
Type 'Promise<void> | Promise<Result>' is not assignable to type 'void | PromiseLike<void>'.
Type 'Promise<Result>' is not assignable to type 'void | PromiseLike<void>'.
Type 'Promise<Result>' is not assignable to type 'PromiseLike<void>'.
Types of property 'then' are incompatible.
Type '<TResult1 = Result, TResult2 = never>(onfulfilled?: ((value: Result) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined) => Promise<...>' is not assignable to type '<TResult1 = void, TResult2 = never>(onfulfilled?: ((value: void) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined) => PromiseLike<...>'.
Types of parameters 'onfulfilled' and 'onfulfilled' are incompatible.
Types of parameters 'value' and 'value' are incompatible.
Type 'Result' is not assignable to type 'void'.
69 const x = await Promise.all([
~
70 this.p1,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...
81 this.p15
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
82 ]);
Если я попытаюсь добавить только (до) 11 звонков,ЛЮБОЙ из них все работает как положено. Как только я добавляю вызов 12-й функции, возникает вышеуказанная ошибка.
Есть что-то, чего мне не хватает, или какой-нибудь обходной путь?