From 478ee1aa68c7919cc78780d4cc1eba90bcfac634 Mon Sep 17 00:00:00 2001 From: Artur Abdullin <30603428+ArturAbdullin@users.noreply.github.com> Date: Wed, 10 Jul 2024 12:26:50 +0300 Subject: [PATCH] feat(CancellablePromise): add the allSettled static method (#13) --- lib/CancellablePromise.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/CancellablePromise.ts b/lib/CancellablePromise.ts index b6628e8..8526d0a 100644 --- a/lib/CancellablePromise.ts +++ b/lib/CancellablePromise.ts @@ -16,6 +16,21 @@ export class CancellablePromise implements Promise { ); } + static allSettled(values: Values) { + function cancel() { + for (const promise of values as CancellablePromise[]) { + promise.cancel(); + } + } + + return new CancellablePromise( + Promise.allSettled(values) as unknown as Promise<{ + -readonly [P in keyof Values]: Awaited; + }>, + cancel, + ); + } + static race(values: Values) { function cancel() { for (const promise of values as CancellablePromise[]) {