diff --git a/lib/utils/debounce.js b/lib/utils/debounce.js index 6fb246052b..cf4311abbc 100644 --- a/lib/utils/debounce.js +++ b/lib/utils/debounce.js @@ -35,8 +35,8 @@ export class Debouncer { this._callback = callback; this._timer = this._asyncModule.run(() => { this._timer = null; - this._callback(); debouncerQueue.delete(this); + this._callback(); }); } /** @@ -161,6 +161,5 @@ export const flushDebouncers = function() { }); } }); - debouncerQueue = new Set(); return didFlush; }; \ No newline at end of file diff --git a/test/unit/debounce.html b/test/unit/debounce.html index 5d20439147..a5a97d599c 100644 --- a/test/unit/debounce.html +++ b/test/unit/debounce.html @@ -38,7 +38,7 @@ suite('enqueueDebouncer & flush', function() { - // NOTE: This is a regression test; the bug it fixed only occured if the + // NOTE: This is a regression test; the bug it fixed only occurred if the // debouncer was flushed before any microtasks run, hence it should be // first in this file test('re-enqueue canceled debouncer', function() { @@ -55,6 +55,16 @@ assert.isTrue(cb.calledOnce); }); + test('flushDebouncers from enqueued debouncer', function(done) { + const cb = sinon.spy(() => flush()); + let db = Debouncer.debounce(null, microTask, cb); + enqueueDebouncer(db); + setTimeout(() => { + assert.isTrue(cb.calledOnce); + done(); + }); + }); + const testEnqueue = (shouldFlush, done) => { const actualOrder = []; const enqueue = (type, {db, cb} = {}) => { @@ -89,6 +99,21 @@ testEnqueue(true, done); }); + test('reentrant flush', function() { + const cb2 = sinon.spy(); + let db2; + const cb1 = sinon.spy(() => { + flush(); + db2 = Debouncer.debounce(null, microTask, cb2); + enqueueDebouncer(db2); + }); + const db1 = Debouncer.debounce(null, microTask, cb1); + enqueueDebouncer(db1); + flush(); + assert.isTrue(cb1.calledOnce); + assert.isTrue(cb2.calledOnce); + }); + }); suite('debounce', function() {