1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-30 13:03:53 +01:00

remove finally() since it is not supported in older browsers

This commit is contained in:
Kyle Spearrin 2019-03-05 17:12:51 -05:00
parent cc27f98aae
commit 965e35604c
2 changed files with 16 additions and 2 deletions

View File

@ -32,11 +32,18 @@ export function sequentialize(cacheKey: (args: any[]) => string) {
return response; return response;
} }
response = originalMethod.apply(this, args).finally(() => { const onFinally = () => {
cache.delete(argsCacheKey); cache.delete(argsCacheKey);
if (cache.size === 0) { if (cache.size === 0) {
caches.delete(this); caches.delete(this);
} }
};
response = originalMethod.apply(this, args).then((val: any) => {
onFinally();
return val;
}).catch((err: any) => {
onFinally();
throw err;
}); });
cache.set(argsCacheKey, response); cache.set(argsCacheKey, response);

View File

@ -32,7 +32,7 @@ export function throttle(limit: number, throttleKey: (args: any[]) => string) {
return new Promise<T>((resolve, reject) => { return new Promise<T>((resolve, reject) => {
const exec = () => { const exec = () => {
originalMethod.apply(this, args).finally(() => { const onFinally = () => {
queue.splice(queue.indexOf(exec), 1); queue.splice(queue.indexOf(exec), 1);
if (queue.length >= limit) { if (queue.length >= limit) {
queue[limit - 1](); queue[limit - 1]();
@ -42,6 +42,13 @@ export function throttle(limit: number, throttleKey: (args: any[]) => string) {
allThrottles.delete(this); allThrottles.delete(this);
} }
} }
};
originalMethod.apply(this, args).then((val: any) => {
onFinally();
return val;
}).catch((err: any) => {
onFinally();
throw err;
}).then(resolve, reject); }).then(resolve, reject);
}; };
queue.push(exec); queue.push(exec);