diff --git a/extensions/git/src/decorators.ts b/extensions/git/src/decorators.ts index 84a09d4562a..c4e46f3458e 100644 --- a/extensions/git/src/decorators.ts +++ b/extensions/git/src/decorators.ts @@ -47,31 +47,31 @@ function _memoize(fn: Function, key: string): Function { export const memoize = decorate(_memoize); -function _throttle(fn: Function): Function { - let current: Promise | undefined; - let next: Promise | undefined; +function _throttle(fn: Function, key: string): Function { + const currentKey = `$throttle$current$${key}`; + const nextKey = `$throttle$next$${key}`; const trigger = function (...args: any[]) { - if (next) { - return next; + if (this[nextKey]) { + return this[nextKey]; } - if (current) { - next = done(current).then(() => { - next = undefined; + if (this[currentKey]) { + this[nextKey] = done(this[currentKey]).then(() => { + this[nextKey] = undefined; return trigger.apply(this, args); }); - return next; + return this[nextKey]; } - current = fn.apply(this, args) as Promise; + this[currentKey] = fn.apply(this, args) as Promise; - done(current).then(() => { - current = undefined; + done(this[currentKey]).then(() => { + this[currentKey] = undefined; }); - return current; + return this[currentKey]; }; return trigger;