Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

fix(AsapScheduler): Fix issue where canceling an asap or animationFrame action early could throw #2638

Merged
merged 1 commit into from
Jun 14, 2017
Merged
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
15 changes: 15 additions & 0 deletions spec/schedulers/AnimationFrameScheduler-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,21 @@ describe('Scheduler.animationFrame', () => {
sandbox.restore();
});

it('should cancel animationFrame actions when delay > 0', () => {
let actionHappened = false;
const sandbox = sinon.sandbox.create();
const fakeTimer = sandbox.useFakeTimers();
animationFrame.schedule(() => {
actionHappened = true;
}, 50).unsubscribe();
expect(actionHappened).to.be.false;
fakeTimer.tick(25);
expect(actionHappened).to.be.false;
fakeTimer.tick(25);
expect(actionHappened).to.be.false;
sandbox.restore();
});

it('should schedule an action to happen later', (done: MochaDone) => {
let actionHappened = false;
animationFrame.schedule(() => {
Expand Down
15 changes: 15 additions & 0 deletions spec/schedulers/AsapScheduler-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,21 @@ describe('Scheduler.asap', () => {
sandbox.restore();
});

it('should cancel asap actions when delay > 0', () => {
let actionHappened = false;
const sandbox = sinon.sandbox.create();
const fakeTimer = sandbox.useFakeTimers();
asap.schedule(() => {
actionHappened = true;
}, 50).unsubscribe();
expect(actionHappened).to.be.false;
fakeTimer.tick(25);
expect(actionHappened).to.be.false;
fakeTimer.tick(25);
expect(actionHappened).to.be.false;
sandbox.restore();
});

it('should schedule an action to happen later', (done: MochaDone) => {
let actionHappened = false;
asap.schedule(() => {
Expand Down
3 changes: 2 additions & 1 deletion src/scheduler/AsyncAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ export class AsyncAction<T> extends Action<T> {
const index = actions.indexOf(this);

this.work = null;
this.delay = null;
this.state = null;
this.pending = false;
this.scheduler = null;
Expand All @@ -149,5 +148,7 @@ export class AsyncAction<T> extends Action<T> {
if (id != null) {
this.id = this.recycleAsyncId(scheduler, id, null);
}

this.delay = null;
}
}