fix(core): fix chained http call (#20924)

Fixes an issue where chained http calls would prematurely call
testability whenStable callbacks after the first http call.

Fixes #20921

PR Close #20924
This commit is contained in:
Benjamin Ingberg
2017-12-10 17:08:12 +01:00
committed by Alex Eagle
parent fb4d84d5b8
commit 7e3f9a482a
2 changed files with 44 additions and 37 deletions

View File

@ -98,13 +98,22 @@ export class Testability implements PublicTestability {
/** @internal */
_runCallbacksIfReady(): void {
if (this.isStable()) {
// Schedules the call backs in a new frame so that it is always async.
scheduleMicroTask(() => {
while (this._callbacks.length !== 0) {
(this._callbacks.pop() !)(this._didWork);
}
if (this._callbacks.length !== 0) {
// Schedules the call backs after a macro task run outside of the angular zone to make sure
// no new task are added
this._ngZone.runOutsideAngular(() => {
setTimeout(() => {
if (this.isStable()) {
while (this._callbacks.length !== 0) {
(this._callbacks.pop() !)(this._didWork);
}
this._didWork = false;
}
});
});
} else {
this._didWork = false;
});
}
} else {
// Not Ready
this._didWork = true;