Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix issue with debounce smaller wait time replacing other timers #366

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions lib/index.ts
Original file line number Diff line number Diff line change
@@ -521,8 +521,13 @@ export default class Backburner {
_timers[argIndex] = args;
} else {
let stack = this._timers[index + 5];
this._timers.splice(i, 0, executeAt, timerId, target, method, args, stack);
this._timers.splice(index, TIMERS_OFFSET);
if (i < index) {
this._timers.splice(index, TIMERS_OFFSET);
this._timers.splice(i, 0, executeAt, timerId, target, method, args, stack);
} else {
this._timers.splice(i, 0, executeAt, timerId, target, method, args, stack);
this._timers.splice(index, TIMERS_OFFSET);
}
}

if (index === 0) {
24 changes: 24 additions & 0 deletions tests/later-test.ts
Original file line number Diff line number Diff line change
@@ -56,6 +56,30 @@ QUnit.test('later', function(assert) {
}, 20);
});

QUnit.test('debounce with later', function(assert) {
assert.expect(3);
let done = assert.async(2);
let bb = new Backburner(['batman']);

function debounceFunc(obj) {
assert.notOk(obj.isFoo, 'debounce called with foo');
assert.ok(obj.isBar, 'debounce called with bar');
done();
}

function laterFunc() {
assert.ok(true, 'later called');
done();
}

const foo = { isFoo: true };
const bar = { isBar: true };

bb.debounce(debounceFunc, foo, 500);
bb.later(laterFunc, 100);
bb.debounce(debounceFunc, bar, 10);
});

QUnit.test('later should rely on stubbed `Date.now`', function(assert) {
assert.expect(1);