Skip to content
Open
Show file tree
Hide file tree
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
Expand Up @@ -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) {
Expand Down
24 changes: 24 additions & 0 deletions tests/later-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down