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

fix(timer): setInterval should not auto cancel after callback invoked, fix rxjs version to pass CI #935

Merged
merged 3 commits into from
Dec 27, 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: 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);
});
});

});