mirror of
https://github.com/bitwarden/browser
synced 2025-12-17 08:43:33 +00:00
formatting
This commit is contained in:
@@ -25,15 +25,14 @@ export function throttle(limit: number, throttleKey: (args: any[]) => string) {
|
|||||||
const throttles = getThrottles(this);
|
const throttles = getThrottles(this);
|
||||||
const argsThrottleKey = throttleKey(args);
|
const argsThrottleKey = throttleKey(args);
|
||||||
let queue = throttles.get(argsThrottleKey);
|
let queue = throttles.get(argsThrottleKey);
|
||||||
if (!queue) {
|
if (queue == null) {
|
||||||
queue = [];
|
queue = [];
|
||||||
throttles.set(argsThrottleKey, queue);
|
throttles.set(argsThrottleKey, queue);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Promise<T>((resolve, reject) => {
|
return new Promise<T>((resolve, reject) => {
|
||||||
const exec = () => {
|
const exec = () => {
|
||||||
originalMethod.apply(this, args)
|
originalMethod.apply(this, args).finally(() => {
|
||||||
.finally(() => {
|
|
||||||
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]();
|
||||||
@@ -43,8 +42,7 @@ export function throttle(limit: number, throttleKey: (args: any[]) => string) {
|
|||||||
allThrottles.delete(this);
|
allThrottles.delete(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
}).then(resolve, reject);
|
||||||
.then(resolve, reject);
|
|
||||||
};
|
};
|
||||||
queue.push(exec);
|
queue.push(exec);
|
||||||
if (queue.length <= limit) {
|
if (queue.length <= limit) {
|
||||||
|
|||||||
Reference in New Issue
Block a user