mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-27 12:36:14 +01:00
remove finally() since it is not supported in older browsers
This commit is contained in:
parent
cc27f98aae
commit
965e35604c
@ -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);
|
||||||
|
@ -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);
|
||||||
|
Loading…
Reference in New Issue
Block a user