|
91 | 91 | this._currentTime = finalTime;
|
92 | 92 | }
|
93 | 93 |
|
94 |
| - flush(limit: number = 20, flushPeriodic = false): number { |
| 94 | + flush(limit = 20, flushPeriodic = false, tick?: (elapsed: number) => void): number { |
95 | 95 | const startTime = this._currentTime;
|
| 96 | + let lastCurrentTime = this._currentTime; |
96 | 97 | let count = 0;
|
97 |
| - let seenTimers: number[] = []; |
| 98 | + const seenTimers: number[] = []; |
98 | 99 | while (this._schedulerQueue.length > 0) {
|
99 | 100 | count++;
|
100 | 101 | if (count > limit) {
|
|
120 | 121 | break;
|
121 | 122 | }
|
122 | 123 | }
|
123 |
| - let current = this._schedulerQueue.shift(); |
| 124 | + const current = this._schedulerQueue.shift(); |
124 | 125 | if (seenTimers.indexOf(current.id) === -1) {
|
125 | 126 | seenTimers.push(current.id);
|
126 | 127 | }
|
| 128 | + lastCurrentTime = this._currentTime; |
127 | 129 | this._currentTime = current.endTime;
|
128 |
| - let retval = current.func.apply(global, current.args); |
| 130 | + if (tick) { |
| 131 | + // Tick any secondary schedulers like Jasmine mock Date. |
| 132 | + tick(this._currentTime - lastCurrentTime); |
| 133 | + } |
| 134 | + const retval = current.func.apply(global, current.args); |
129 | 135 | if (!retval) {
|
130 | 136 | // Uncaught exception in the current scheduled function. Stop processing the queue.
|
131 | 137 | break;
|
|
271 | 277 | flushErrors();
|
272 | 278 | }
|
273 | 279 |
|
274 |
| - flush(limit?: number, flushPeriodic?: boolean): number { |
| 280 | + flush(limit?: number, flushPeriodic?: boolean, tick?: (elapsed: number) => void): number { |
275 | 281 | FakeAsyncTestZoneSpec.assertInZone();
|
276 | 282 | this.flushMicrotasks();
|
277 |
| - let elapsed = this._scheduler.flush(limit, flushPeriodic); |
| 283 | + const elapsed = this._scheduler.flush(limit, flushPeriodic, tick); |
278 | 284 | if (this._lastError !== null) {
|
279 | 285 | this._resetLastErrorAndThrow();
|
280 | 286 | }
|
|
0 commit comments