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

fix(task): eventTask/Periodical task should not be reset after being cancelled when running #642

Merged
merged 1 commit into from
Mar 7, 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
6 changes: 5 additions & 1 deletion lib/zone.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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