forked from angular/angular
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(core): Update usage of pending tasks to make stability async
This commit updates the public `ExperimentalPendingTasks` to remove tasks asynchronously. This is true today for ZoneJS already - it waits a microtask and checks the zone state again before deciding it's stable. As we've continued to work with the pending tasks API in various places, we've continued to encounter difficulty with the synchronous handling of stability. This change will ensure that synchronous code that executes after the last pending task is removed can add another task and keep the application unstable without it flipping first to stable (and thus causing SSR serialization too early).
- Loading branch information
Showing
18 changed files
with
124 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import {BehaviorSubject} from 'rxjs'; | ||
|
||
import {inject} from '../di/injector_compatibility'; | ||
import {ɵɵdefineInjectable} from '../di/interface/defs'; | ||
import {OnDestroy} from '../interface/lifecycle_hooks'; | ||
|
||
/** | ||
* Internal implementation of the pending tasks service. | ||
*/ | ||
export class PendingTasks implements OnDestroy { | ||
private taskId = 0; | ||
private pendingTasks = new Set<number>(); | ||
private get _hasPendingTasks() { | ||
return this.hasPendingTasks.value; | ||
} | ||
hasPendingTasks = new BehaviorSubject<boolean>(false); | ||
|
||
add(): number { | ||
if (!this._hasPendingTasks) { | ||
this.hasPendingTasks.next(true); | ||
} | ||
const taskId = this.taskId++; | ||
this.pendingTasks.add(taskId); | ||
return taskId; | ||
} | ||
|
||
remove(taskId: number): void { | ||
this.pendingTasks.delete(taskId); | ||
if (this.pendingTasks.size === 0 && this._hasPendingTasks) { | ||
this.hasPendingTasks.next(false); | ||
} | ||
} | ||
|
||
ngOnDestroy(): void { | ||
this.pendingTasks.clear(); | ||
if (this._hasPendingTasks) { | ||
this.hasPendingTasks.next(false); | ||
} | ||
} | ||
|
||
/** @nocollapse */ | ||
static ɵprov = /** @pureOrBreakMyCode */ ɵɵdefineInjectable({ | ||
token: PendingTasks, | ||
providedIn: 'root', | ||
factory: () => new PendingTasks(), | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.