From 965e35604c584f7dcf786f04933c9b2fcf8a4ba0 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Tue, 5 Mar 2019 17:12:51 -0500 Subject: [PATCH] remove finally() since it is not supported in older browsers --- src/misc/sequentialize.ts | 9 ++++++++- src/misc/throttle.ts | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/misc/sequentialize.ts b/src/misc/sequentialize.ts index ab64074472e..ff8c4856b09 100644 --- a/src/misc/sequentialize.ts +++ b/src/misc/sequentialize.ts @@ -32,11 +32,18 @@ export function sequentialize(cacheKey: (args: any[]) => string) { return response; } - response = originalMethod.apply(this, args).finally(() => { + const onFinally = () => { cache.delete(argsCacheKey); if (cache.size === 0) { caches.delete(this); } + }; + response = originalMethod.apply(this, args).then((val: any) => { + onFinally(); + return val; + }).catch((err: any) => { + onFinally(); + throw err; }); cache.set(argsCacheKey, response); diff --git a/src/misc/throttle.ts b/src/misc/throttle.ts index 3a295ba69d4..cc60c6aaf64 100644 --- a/src/misc/throttle.ts +++ b/src/misc/throttle.ts @@ -32,7 +32,7 @@ export function throttle(limit: number, throttleKey: (args: any[]) => string) { return new Promise((resolve, reject) => { const exec = () => { - originalMethod.apply(this, args).finally(() => { + const onFinally = () => { queue.splice(queue.indexOf(exec), 1); if (queue.length >= limit) { queue[limit - 1](); @@ -42,6 +42,13 @@ export function throttle(limit: number, throttleKey: (args: any[]) => string) { allThrottles.delete(this); } } + }; + originalMethod.apply(this, args).then((val: any) => { + onFinally(); + return val; + }).catch((err: any) => { + onFinally(); + throw err; }).then(resolve, reject); }; queue.push(exec);