diff --git a/src/vs/base/common/decorators.ts b/src/vs/base/common/decorators.ts index 080ac3dc295..719407fe245 100644 --- a/src/vs/base/common/decorators.ts +++ b/src/vs/base/common/decorators.ts @@ -66,10 +66,10 @@ export interface IDebouceReducer { (previousValue: T, ...args: any[]): T; } -export function debounce(delay: number, reducer?: IDebouceReducer, initialValue?: T): Function { +export function debounce(delay: number, reducer?: IDebouceReducer, initialValueProvider?: () => T): Function { return createDecorator((fn, key) => { const timerKey = `$debounce$${key}`; - let result = initialValue; + let result = initialValueProvider ? initialValueProvider() : void 0; return function (this: any, ...args: any[]) { clearTimeout(this[timerKey]); @@ -79,7 +79,10 @@ export function debounce(delay: number, reducer?: IDebouceReducer, initial args = [result]; } - this[timerKey] = setTimeout(() => fn.apply(this, args), delay); + this[timerKey] = setTimeout(() => { + fn.apply(this, args); + result = initialValueProvider ? initialValueProvider() : void 0; + }, delay); }; }); } \ No newline at end of file diff --git a/src/vs/workbench/api/node/extHostProgress.ts b/src/vs/workbench/api/node/extHostProgress.ts index 3826c76bc3c..b0f1f4d5143 100644 --- a/src/vs/workbench/api/node/extHostProgress.ts +++ b/src/vs/workbench/api/node/extHostProgress.ts @@ -83,7 +83,7 @@ class ProgressCallback extends Progress { super(p => this.throttledReport(p)); } - @debounce(100, (result: IProgressStep, currentValue: IProgressStep) => mergeProgress(result, currentValue), Object.create(null)) + @debounce(100, (result: IProgressStep, currentValue: IProgressStep) => mergeProgress(result, currentValue), () => Object.create(null)) throttledReport(p: IProgressStep): void { this._proxy.$progressReport(this._handle, p); }