Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
fix(task): fix #638, eventTask/Periodical task should not be reset af…
Browse files Browse the repository at this point in the history
…ter cancel in running state (#642)
  • Loading branch information
JiaLiPassion authored and mhevery committed Mar 7, 2017
1 parent 0534b19 commit eb9250d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/zone.ts
Expand Up @@ -754,7 +754,11 @@ const Zone: ZoneType = (function(global: any) {
}
} finally {
if (task.type == eventTask || (task.data && task.data.isPeriodic)) {
reEntryGuard && (task as ZoneTask)._transitionTo(scheduled, running, notScheduled);
// if the task's state is notScheduled, then it has already been cancelled
// we should not reset the state to scheduled
if (task.state !== notScheduled) {
reEntryGuard && (task as ZoneTask)._transitionTo(scheduled, running);
}
} else {
task.runCount = 0;
this._updateTaskCount(task as ZoneTask, -1);
Expand Down
24 changes: 24 additions & 0 deletions test/common/zone.spec.ts
Expand Up @@ -299,6 +299,30 @@ describe('Zone', function() {
]);
});

it('period task should not transit to scheduled state after being cancelled in running state',
() => {
const zone = Zone.current.fork({name: 'testZone'});

const task = zone.scheduleMacroTask('testPeriodTask', () => {
zone.cancelTask(task);
}, {isPeriodic: true}, () => {}, () => {});

task.invoke();
expect(task.state).toBe('notScheduled');
});

it('event task should not transit to scheduled state after being cancelled in running state',
() => {
const zone = Zone.current.fork({name: 'testZone'});

const task = zone.scheduleEventTask('testEventTask', () => {
zone.cancelTask(task);
}, null, () => {}, () => {});

task.invoke();
expect(task.state).toBe('notScheduled');
});

describe('assert ZoneAwarePromise', () => {
it('should not throw when all is OK', () => {
Zone.assertZonePatched();
Expand Down

0 comments on commit eb9250d

Please sign in to comment.