Skip to content

Commit

Permalink
fix(NextTickAction): fix unsubscription behavior
Browse files Browse the repository at this point in the history
- fix clearImmediate behavior prevents nextTickScheduler throws if it's
being used multiple time

closes #582
  • Loading branch information
kwonoj authored and benlesh committed Oct 26, 2015
1 parent 9f1722b commit 3d8264c
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/schedulers/NextTickAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import ImmediateAction from './ImmediateAction';
import Action from './Action';

export default class NextTickAction<T> extends ImmediateAction<T> {

id: number;
private id: any;

schedule(state?: any): Action {
if (this.isUnsubscribed) {
Expand All @@ -21,7 +20,7 @@ export default class NextTickAction<T> extends ImmediateAction<T> {
if (!scheduler.scheduled) {
scheduler.scheduled = true;
this.id = Immediate.setImmediate(() => {
this.id = void 0;
this.id = null;
this.scheduler.scheduled = false;
this.scheduler.flush();
});
Expand All @@ -30,8 +29,7 @@ export default class NextTickAction<T> extends ImmediateAction<T> {
return this;
}

unsubscribe() {

unsubscribe(): void {
const id = this.id;
const scheduler = this.scheduler;

Expand All @@ -40,10 +38,11 @@ export default class NextTickAction<T> extends ImmediateAction<T> {
if (scheduler.actions.length === 0) {
scheduler.active = false;
scheduler.scheduled = false;
if (id) {
this.id = void 0;
Immediate.clearImmediate(id);
}
}

if (id) {
this.id = null;
Immediate.clearImmediate(id);
}
}
}

0 comments on commit 3d8264c

Please sign in to comment.