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

Commit b7b1743

Browse files
JiaLiPassionmhevery
authored andcommitted
fix(timer): setInterval should not auto cancel after callback invoked, fix rxjs version to pass CI (#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
1 parent 8b03980 commit b7b1743

File tree

4 files changed

+35
-2
lines changed

4 files changed

+35
-2
lines changed

lib/common/timers.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ export function patchTimer(window: any, setName: string, cancelName: string, nam
3939
try {
4040
task.invoke.apply(this, arguments);
4141
} finally {
42+
if (task.data && task.data.isPeriodic) {
43+
// issue-934, task will be cancelled
44+
// even it is a periodic task such as
45+
// setInterval
46+
return;
47+
}
4248
if (typeof data.handleId === NUMBER) {
4349
// in non-nodejs env, we remove timerId
4450
// from local cache

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
"phantomjs": "^2.1.7",
8888
"promises-aplus-tests": "^2.1.2",
8989
"pump": "^1.0.1",
90-
"rxjs": "^5.4.2",
90+
"rxjs": "^5.5.3",
9191
"selenium-webdriver": "^3.4.0",
9292
"systemjs": "^0.19.37",
9393
"ts-loader": "^0.6.0",

test/browser/requestAnimationFrame.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ describe('requestAnimationFrame', function() {
2626

2727
it('should bind to same zone when called recursively', function(done) {
2828
const originalTimeout: number = (<any>jasmine).DEFAULT_TIMEOUT_INTERVAL;
29-
(<any>jasmine).DEFAULT_TIMEOUT_INTERVAL = 5000;
29+
(<any>jasmine).DEFAULT_TIMEOUT_INTERVAL = 10000;
3030
Zone.current.fork({name: 'TestZone'}).run(() => {
3131
let frames = 0;
3232
let previousTimeStamp = 0;

test/common/setInterval.spec.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,31 @@ describe('setInterval', function() {
6060
}, null, null, 'unit-test');
6161
});
6262

63+
it('should not cancel the task after invoke the setInterval callback', (done) => {
64+
const logs: HasTaskState[] = [];
65+
const zone = Zone.current.fork({
66+
name: 'interval',
67+
onHasTask:
68+
(delegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, hasTask: HasTaskState) => {
69+
logs.push(hasTask);
70+
return delegate.hasTask(targetZone, hasTask);
71+
}
72+
});
73+
74+
zone.run(() => {
75+
const timerId = setInterval(() => {}, 100);
76+
(global as any)[Zone.__symbol__('setTimeout')](() => {
77+
expect(logs.length > 0).toBeTruthy();
78+
expect(logs).toEqual(
79+
[{microTask: false, macroTask: true, eventTask: false, change: 'macroTask'}]);
80+
clearInterval(timerId);
81+
expect(logs).toEqual([
82+
{microTask: false, macroTask: true, eventTask: false, change: 'macroTask'},
83+
{microTask: false, macroTask: false, eventTask: false, change: 'macroTask'}
84+
]);
85+
done();
86+
}, 300);
87+
});
88+
});
89+
6390
});

0 commit comments

Comments
 (0)