Skip to content

Commit

Permalink
fix(timer): setInterval should not auto cancel after callback invoked…
Browse files Browse the repository at this point in the history
…, fix rxjs version to pass CI (angular#935)

* fix(timer): setInterval should not auto cancel after callback invoked

* fix rxjs to 5.4.2

* fix(test): update rxjs to 5.5.3, update RAF test case to avoid timeout
  • Loading branch information
JiaLiPassion authored and mhevery committed Dec 27, 2017
1 parent 8b03980 commit b7b1743
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
6 changes: 6 additions & 0 deletions lib/common/timers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ export function patchTimer(window: any, setName: string, cancelName: string, nam
try {
task.invoke.apply(this, arguments);
} finally {
if (task.data && task.data.isPeriodic) {
// issue-934, task will be cancelled
// even it is a periodic task such as
// setInterval
return;
}
if (typeof data.handleId === NUMBER) {
// in non-nodejs env, we remove timerId
// from local cache
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
"phantomjs": "^2.1.7",
"promises-aplus-tests": "^2.1.2",
"pump": "^1.0.1",
"rxjs": "^5.4.2",
"rxjs": "^5.5.3",
"selenium-webdriver": "^3.4.0",
"systemjs": "^0.19.37",
"ts-loader": "^0.6.0",
Expand Down
2 changes: 1 addition & 1 deletion test/browser/requestAnimationFrame.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('requestAnimationFrame', function() {

it('should bind to same zone when called recursively', function(done) {
const originalTimeout: number = (<any>jasmine).DEFAULT_TIMEOUT_INTERVAL;
(<any>jasmine).DEFAULT_TIMEOUT_INTERVAL = 5000;
(<any>jasmine).DEFAULT_TIMEOUT_INTERVAL = 10000;
Zone.current.fork({name: 'TestZone'}).run(() => {
let frames = 0;
let previousTimeStamp = 0;
Expand Down
27 changes: 27 additions & 0 deletions test/common/setInterval.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,31 @@ describe('setInterval', function() {
}, null, null, 'unit-test');
});

it('should not cancel the task after invoke the setInterval callback', (done) => {
const logs: HasTaskState[] = [];
const zone = Zone.current.fork({
name: 'interval',
onHasTask:
(delegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, hasTask: HasTaskState) => {
logs.push(hasTask);
return delegate.hasTask(targetZone, hasTask);
}
});

zone.run(() => {
const timerId = setInterval(() => {}, 100);
(global as any)[Zone.__symbol__('setTimeout')](() => {
expect(logs.length > 0).toBeTruthy();
expect(logs).toEqual(
[{microTask: false, macroTask: true, eventTask: false, change: 'macroTask'}]);
clearInterval(timerId);
expect(logs).toEqual([
{microTask: false, macroTask: true, eventTask: false, change: 'macroTask'},
{microTask: false, macroTask: false, eventTask: false, change: 'macroTask'}
]);
done();
}, 300);
});
});

});

0 comments on commit b7b1743

Please sign in to comment.