Skip to content

Commit cd59e5d

Browse files
alxhubAndrewKushnir
authored andcommitted
refactor(core): avoid removing pending tasks twice (angular#58255)
Optimizes `PendingTasks` slightly to avoid notifying the scheduler if the disposal function of a pending task is called twice. PR Close angular#58255
1 parent 9544930 commit cd59e5d

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

packages/core/src/pending_tasks.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ export class PendingTasksInternal implements OnDestroy {
3636
return taskId;
3737
}
3838

39+
has(taskId: number): boolean {
40+
return this.pendingTasks.has(taskId);
41+
}
42+
3943
remove(taskId: number): void {
4044
this.pendingTasks.delete(taskId);
4145
if (this.pendingTasks.size === 0 && this._hasPendingTasks) {
@@ -90,6 +94,10 @@ export class PendingTasks {
9094
add(): () => void {
9195
const taskId = this.internalPendingTasks.add();
9296
return () => {
97+
if (!this.internalPendingTasks.has(taskId)) {
98+
// This pending task has already been cleared.
99+
return;
100+
}
93101
// Notifying the scheduler will hold application stability open until the next tick.
94102
this.scheduler.notify(NotificationSource.PendingTaskRemoved);
95103
this.internalPendingTasks.remove(taskId);

0 commit comments

Comments
 (0)