Skip to content

Commit fc39043

Browse files
trxcllntbenlesh
authored andcommitted
fix(Schedulers): Fix issue where canceling an asap or animationFrame action early could throw (#2638)
1 parent c250afc commit fc39043

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

spec/schedulers/AnimationFrameScheduler-spec.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,21 @@ describe('Scheduler.animationFrame', () => {
2525
sandbox.restore();
2626
});
2727

28+
it('should cancel animationFrame actions when delay > 0', () => {
29+
let actionHappened = false;
30+
const sandbox = sinon.sandbox.create();
31+
const fakeTimer = sandbox.useFakeTimers();
32+
animationFrame.schedule(() => {
33+
actionHappened = true;
34+
}, 50).unsubscribe();
35+
expect(actionHappened).to.be.false;
36+
fakeTimer.tick(25);
37+
expect(actionHappened).to.be.false;
38+
fakeTimer.tick(25);
39+
expect(actionHappened).to.be.false;
40+
sandbox.restore();
41+
});
42+
2843
it('should schedule an action to happen later', (done: MochaDone) => {
2944
let actionHappened = false;
3045
animationFrame.schedule(() => {

spec/schedulers/AsapScheduler-spec.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,21 @@ describe('Scheduler.asap', () => {
2525
sandbox.restore();
2626
});
2727

28+
it('should cancel asap actions when delay > 0', () => {
29+
let actionHappened = false;
30+
const sandbox = sinon.sandbox.create();
31+
const fakeTimer = sandbox.useFakeTimers();
32+
asap.schedule(() => {
33+
actionHappened = true;
34+
}, 50).unsubscribe();
35+
expect(actionHappened).to.be.false;
36+
fakeTimer.tick(25);
37+
expect(actionHappened).to.be.false;
38+
fakeTimer.tick(25);
39+
expect(actionHappened).to.be.false;
40+
sandbox.restore();
41+
});
42+
2843
it('should schedule an action to happen later', (done: MochaDone) => {
2944
let actionHappened = false;
3045
asap.schedule(() => {

src/scheduler/AsyncAction.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ export class AsyncAction<T> extends Action<T> {
137137
const index = actions.indexOf(this);
138138

139139
this.work = null;
140-
this.delay = null;
141140
this.state = null;
142141
this.pending = false;
143142
this.scheduler = null;
@@ -149,5 +148,7 @@ export class AsyncAction<T> extends Action<T> {
149148
if (id != null) {
150149
this.id = this.recycleAsyncId(scheduler, id, null);
151150
}
151+
152+
this.delay = null;
152153
}
153154
}

0 commit comments

Comments
 (0)