refactor(async): extract timer related functions into a TimerWrapper
This commit is contained in:
@@ -5,7 +5,7 @@ import {IMPLEMENTS} from 'angular2/src/facade/lang';
|
||||
import {WrappedValue} from 'angular2/src/change_detection/pipes/pipe';
|
||||
import {ObservablePipe} from 'angular2/src/change_detection/pipes/observable_pipe';
|
||||
import {ChangeDetectorRef} from 'angular2/src/change_detection/change_detector_ref';
|
||||
import {EventEmitter, Observable, ObservableWrapper, PromiseWrapper} from 'angular2/src/facade/async';
|
||||
import {EventEmitter, Observable, ObservableWrapper, TimerWrapper} from 'angular2/src/facade/async';
|
||||
|
||||
export function main() {
|
||||
describe("ObservablePipe", () => {
|
||||
@@ -41,7 +41,7 @@ export function main() {
|
||||
|
||||
ObservableWrapper.callNext(emitter, message);
|
||||
|
||||
PromiseWrapper.setTimeout(() => {
|
||||
TimerWrapper.setTimeout(() => {
|
||||
expect(pipe.transform(emitter)).toEqual(new WrappedValue(message));
|
||||
async.done();
|
||||
}, 0)
|
||||
@@ -52,7 +52,7 @@ export function main() {
|
||||
pipe.transform(emitter);
|
||||
ObservableWrapper.callNext(emitter, message);
|
||||
|
||||
PromiseWrapper.setTimeout(() => {
|
||||
TimerWrapper.setTimeout(() => {
|
||||
pipe.transform(emitter);
|
||||
expect(pipe.transform(emitter)).toBe(message);
|
||||
async.done();
|
||||
@@ -69,7 +69,7 @@ export function main() {
|
||||
// this should not affect the pipe
|
||||
ObservableWrapper.callNext(emitter, message);
|
||||
|
||||
PromiseWrapper.setTimeout(() => {
|
||||
TimerWrapper.setTimeout(() => {
|
||||
expect(pipe.transform(newEmitter)).toBe(null);
|
||||
async.done();
|
||||
}, 0)
|
||||
@@ -80,7 +80,7 @@ export function main() {
|
||||
pipe.transform(emitter);
|
||||
ObservableWrapper.callNext(emitter, message);
|
||||
|
||||
PromiseWrapper.setTimeout(() => {
|
||||
TimerWrapper.setTimeout(() => {
|
||||
expect(ref.spy('requestCheck')).toHaveBeenCalled();
|
||||
async.done();
|
||||
}, 0)
|
||||
@@ -98,7 +98,7 @@ export function main() {
|
||||
|
||||
ObservableWrapper.callNext(emitter, message);
|
||||
|
||||
PromiseWrapper.setTimeout(() => {
|
||||
TimerWrapper.setTimeout(() => {
|
||||
expect(pipe.transform(emitter)).toBe(null);
|
||||
async.done();
|
||||
}, 0)
|
||||
|
||||
@@ -4,7 +4,7 @@ import {IMPLEMENTS} from 'angular2/src/facade/lang';
|
||||
import {PromisePipe} from 'angular2/src/change_detection/pipes/promise_pipe';
|
||||
import {WrappedValue} from 'angular2/src/change_detection/pipes/pipe';
|
||||
import {ChangeDetectorRef} from 'angular2/src/change_detection/change_detector_ref';
|
||||
import {PromiseWrapper} from 'angular2/src/facade/async';
|
||||
import {PromiseWrapper, TimerWrapper} from 'angular2/src/facade/async';
|
||||
|
||||
export function main() {
|
||||
describe("PromisePipe", () => {
|
||||
@@ -40,7 +40,7 @@ export function main() {
|
||||
|
||||
completer.resolve(message);
|
||||
|
||||
PromiseWrapper.setTimeout(() => {
|
||||
TimerWrapper.setTimeout(() => {
|
||||
expect(pipe.transform(completer.promise)).toEqual(new WrappedValue(message));
|
||||
async.done();
|
||||
}, 0)
|
||||
@@ -51,7 +51,7 @@ export function main() {
|
||||
pipe.transform(completer.promise);
|
||||
completer.resolve(message);
|
||||
|
||||
PromiseWrapper.setTimeout(() => {
|
||||
TimerWrapper.setTimeout(() => {
|
||||
pipe.transform(completer.promise);
|
||||
expect(pipe.transform(completer.promise)).toBe(message);
|
||||
async.done();
|
||||
@@ -68,7 +68,7 @@ export function main() {
|
||||
// this should not affect the pipe, so it should return WrappedValue
|
||||
completer.resolve(message);
|
||||
|
||||
PromiseWrapper.setTimeout(() => {
|
||||
TimerWrapper.setTimeout(() => {
|
||||
expect(pipe.transform(newCompleter.promise)).toBe(null);
|
||||
async.done();
|
||||
}, 0)
|
||||
@@ -79,7 +79,7 @@ export function main() {
|
||||
pipe.transform(completer.promise);
|
||||
completer.resolve(message);
|
||||
|
||||
PromiseWrapper.setTimeout(() => {
|
||||
TimerWrapper.setTimeout(() => {
|
||||
expect(ref.spy('requestCheck')).toHaveBeenCalled();
|
||||
async.done();
|
||||
}, 0)
|
||||
|
||||
+6
-6
@@ -13,7 +13,7 @@ import {
|
||||
isInInnerZone
|
||||
} from 'angular2/test_lib';
|
||||
|
||||
import {PromiseWrapper} from 'angular2/src/facade/async';
|
||||
import {PromiseWrapper, TimerWrapper} from 'angular2/src/facade/async';
|
||||
import {ListWrapper} from 'angular2/src/facade/collection';
|
||||
import {BaseException} from 'angular2/src/facade/lang';
|
||||
|
||||
@@ -21,7 +21,7 @@ import {NgZone} from 'angular2/src/core/zone/ng_zone';
|
||||
|
||||
// Schedules a macrotask (using a timer)
|
||||
function macroTask(fn: Function): void {
|
||||
_zone.runOutsideAngular(() => PromiseWrapper.setTimeout(fn, 1));
|
||||
_zone.runOutsideAngular(() => TimerWrapper.setTimeout(fn, 1));
|
||||
}
|
||||
|
||||
// Schedules a microtasks (using a resolved promise .then())
|
||||
@@ -71,8 +71,8 @@ export function main() {
|
||||
var c = PromiseWrapper.completer();
|
||||
|
||||
_zone.run(() => {
|
||||
PromiseWrapper.setTimeout(() => {
|
||||
PromiseWrapper.setTimeout(() => {
|
||||
TimerWrapper.setTimeout(() => {
|
||||
TimerWrapper.setTimeout(() => {
|
||||
c.resolve(null);
|
||||
throw new BaseException('ccc');
|
||||
}, 0);
|
||||
@@ -124,8 +124,8 @@ export function main() {
|
||||
var c = PromiseWrapper.completer();
|
||||
|
||||
_zone.run(() => {
|
||||
PromiseWrapper.setTimeout(() => {
|
||||
PromiseWrapper.setTimeout(() => {
|
||||
TimerWrapper.setTimeout(() => {
|
||||
TimerWrapper.setTimeout(() => {
|
||||
c.resolve(null);
|
||||
throw new BaseException('ccc');
|
||||
}, 0);
|
||||
|
||||
+20
-20
@@ -14,7 +14,7 @@ import {
|
||||
tick,
|
||||
xit
|
||||
} from 'angular2/test_lib';
|
||||
import {PromiseWrapper} from 'angular2/src/facade/async';
|
||||
import {TimerWrapper, PromiseWrapper} from 'angular2/src/facade/async';
|
||||
import {BaseException, global} from 'angular2/src/facade/lang';
|
||||
import {Parser} from 'angular2/change_detection';
|
||||
|
||||
@@ -120,7 +120,7 @@ export function main() {
|
||||
describe('timers', () => {
|
||||
it('should run queued zero duration timer on zero tick', fakeAsync(() => {
|
||||
var ran = false;
|
||||
PromiseWrapper.setTimeout(() => { ran = true }, 0);
|
||||
TimerWrapper.setTimeout(() => { ran = true }, 0);
|
||||
|
||||
expect(ran).toEqual(false);
|
||||
|
||||
@@ -131,7 +131,7 @@ export function main() {
|
||||
|
||||
it('should run queued timer after sufficient clock ticks', fakeAsync(() => {
|
||||
var ran = false;
|
||||
PromiseWrapper.setTimeout(() => { ran = true; }, 10);
|
||||
TimerWrapper.setTimeout(() => { ran = true; }, 10);
|
||||
|
||||
tick(6);
|
||||
expect(ran).toEqual(false);
|
||||
@@ -142,7 +142,7 @@ export function main() {
|
||||
|
||||
it('should run queued timer only once', fakeAsync(() => {
|
||||
var cycles = 0;
|
||||
PromiseWrapper.setTimeout(() => { cycles++; }, 10);
|
||||
TimerWrapper.setTimeout(() => { cycles++; }, 10);
|
||||
|
||||
tick(10);
|
||||
expect(cycles).toEqual(1);
|
||||
@@ -156,8 +156,8 @@ export function main() {
|
||||
|
||||
it('should not run cancelled timer', fakeAsync(() => {
|
||||
var ran = false;
|
||||
var id = PromiseWrapper.setTimeout(() => { ran = true; }, 10);
|
||||
PromiseWrapper.clearTimeout(id);
|
||||
var id = TimerWrapper.setTimeout(() => { ran = true; }, 10);
|
||||
TimerWrapper.clearTimeout(id);
|
||||
|
||||
tick(10);
|
||||
expect(ran).toEqual(false);
|
||||
@@ -168,7 +168,7 @@ export function main() {
|
||||
if (IS_DARTIUM) return;
|
||||
expect(() => {
|
||||
fakeAsync(() => {
|
||||
PromiseWrapper.setTimeout(() => { }, 10);
|
||||
TimerWrapper.setTimeout(() => { }, 10);
|
||||
})();
|
||||
}).toThrowError('1 timer(s) still in the queue.');
|
||||
});
|
||||
@@ -178,14 +178,14 @@ export function main() {
|
||||
if (IS_DARTIUM) return;
|
||||
expect(() => {
|
||||
fakeAsync(() => {
|
||||
PromiseWrapper.setInterval(() => { }, 10);
|
||||
TimerWrapper.setInterval(() => { }, 10);
|
||||
})();
|
||||
}).toThrowError('1 periodic timer(s) still in the queue.');
|
||||
});
|
||||
|
||||
it('should run periodic timers', fakeAsync(() => {
|
||||
var cycles = 0;
|
||||
var id = PromiseWrapper.setInterval(() => { cycles++; }, 10);
|
||||
var id = TimerWrapper.setInterval(() => { cycles++; }, 10);
|
||||
|
||||
tick(10);
|
||||
expect(cycles).toEqual(1);
|
||||
@@ -196,13 +196,13 @@ export function main() {
|
||||
tick(10);
|
||||
expect(cycles).toEqual(3);
|
||||
|
||||
PromiseWrapper.clearInterval(id);
|
||||
TimerWrapper.clearInterval(id);
|
||||
}));
|
||||
|
||||
it('should not run cancelled periodic timer', fakeAsync(() => {
|
||||
var ran = false;
|
||||
var id = PromiseWrapper.setInterval(() => { ran = true; }, 10);
|
||||
PromiseWrapper.clearInterval(id);
|
||||
var id = TimerWrapper.setInterval(() => { ran = true; }, 10);
|
||||
TimerWrapper.clearInterval(id);
|
||||
|
||||
tick(10);
|
||||
expect(ran).toEqual(false);
|
||||
@@ -218,9 +218,9 @@ export function main() {
|
||||
var cycles = 0;
|
||||
var id;
|
||||
|
||||
id = PromiseWrapper.setInterval(() => {
|
||||
id = TimerWrapper.setInterval(() => {
|
||||
cycles++;
|
||||
PromiseWrapper.clearInterval(id);
|
||||
TimerWrapper.clearInterval(id);
|
||||
}, 10);
|
||||
|
||||
tick(10);
|
||||
@@ -235,16 +235,16 @@ export function main() {
|
||||
|
||||
PromiseWrapper.resolve(null).then((_) => log.add('microtask'));
|
||||
|
||||
PromiseWrapper.setTimeout(() => log.add('timer'), 9);
|
||||
TimerWrapper.setTimeout(() => log.add('timer'), 9);
|
||||
|
||||
var id = PromiseWrapper.setInterval(() => log.add('periodic timer'), 10);
|
||||
var id = TimerWrapper.setInterval(() => log.add('periodic timer'), 10);
|
||||
|
||||
expect(log.result()).toEqual('');
|
||||
|
||||
tick(10);
|
||||
expect(log.result()).toEqual('microtask; timer; periodic timer');
|
||||
|
||||
PromiseWrapper.clearInterval(id);
|
||||
TimerWrapper.clearInterval(id);
|
||||
}));
|
||||
|
||||
it('should process micro-tasks created in timers before next timers', fakeAsync(() => {
|
||||
@@ -252,12 +252,12 @@ export function main() {
|
||||
|
||||
PromiseWrapper.resolve(null).then((_) => log.add('microtask'));
|
||||
|
||||
PromiseWrapper.setTimeout(() => {
|
||||
TimerWrapper.setTimeout(() => {
|
||||
log.add('timer');
|
||||
PromiseWrapper.resolve(null).then((_) => log.add('t microtask'));
|
||||
}, 9);
|
||||
|
||||
var id = PromiseWrapper.setInterval(() => {
|
||||
var id = TimerWrapper.setInterval(() => {
|
||||
log.add('periodic timer');
|
||||
PromiseWrapper.resolve(null).then((_) => log.add('pt microtask'));
|
||||
}, 10);
|
||||
@@ -268,7 +268,7 @@ export function main() {
|
||||
tick(10);
|
||||
expect(log.result()).toEqual('microtask; timer; t microtask; periodic timer; pt microtask; periodic timer; pt microtask');
|
||||
|
||||
PromiseWrapper.clearInterval(id);
|
||||
TimerWrapper.clearInterval(id);
|
||||
}));
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user