mirror of
https://github.com/bitwarden/browser.git
synced 2024-10-05 05:17:40 +02:00
formatting
This commit is contained in:
parent
db37a831e4
commit
4634dd2e83
@ -25,26 +25,24 @@ 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]();
|
} else if (queue.length === 0) {
|
||||||
} else if (queue.length === 0) {
|
throttles.delete(argsThrottleKey);
|
||||||
throttles.delete(argsThrottleKey);
|
if (throttles.size === 0) {
|
||||||
if (throttles.size === 0) {
|
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) {
|
||||||
|
Loading…
Reference in New Issue
Block a user