49
50
constructor(
52
>
public readonly _runFn: (reader: IReaderWithStore, changeSummary: TChangeSummary) => void,
53
>
private readonly _changeTracker: IChangeTracker<TChangeSummary> | undefined,
54
>
debugLocation: DebugLocation
55
>
) {
56
>
this._changeSummary = this._changeTracker?.createChangeSummary(undefined);
57
>
getLogger()?.handleAutorunCreated(this, debugLocation);
58
>
this._run();
59
>
60
>
trackDisposable(this);
61
>
}
62
63
public dispose(): void {
65
return;
66
}
68
>
for (const o of this._dependencies) {
69
>
o.removeObserver(this); // Warning: external call!
70
>
}
71
>
this._dependencies.clear();
72
>
73
>
if (this._store !== undefined) {
74
this._store.dispose();
75
}
77
this._delayedStore.dispose();
78
}
80
>
getLogger()?.handleAutorunDisposed(this);
81
>
markAsDisposed(this);
82
>
}
83
84
private _run() {
86
>
this._dependenciesToBeRemoved = this._dependencies;
87
>
this._dependencies = emptySet;
88
>
89
>
this._state = AutorunState.upToDate;
90
>
91
>
try {
92
>
if (!this._disposed) {
93
>
getLogger()?.handleAutorunStarted(this);
94
>
const changeSummary = this._changeSummary!;
95
>
const delayedStore = this._delayedStore;
96
>
if (delayedStore !== undefined) {
97
this._delayedStore = undefined;
98
}
100
>
this._isRunning = true;
101
>
if (this._changeTracker) {
102
this._changeTracker.beforeUpdate?.(this, changeSummary);
103
this._changeSummary = this._changeTracker.createChangeSummary(changeSummary); // Warning: external call!
104
}
106
this._store.dispose();
107
this._store = undefined;
108
}
110
>
this._runFn(this, changeSummary); // Warning: external call!
111
>
} catch (e) {
112
onBugIndicatingError(e);
114
>
this._isRunning = false;
115
>
if (delayedStore !== undefined) {
116
delayedStore.dispose();
117
}
119
>
}
120
>
} finally {
121
>
if (!this._disposed) {
122
>
getLogger()?.handleAutorunFinished(this);
123
>
}
124
>
// We don't want our observed observables to think that they are (not even temporarily) not being observed.
125
>
// Thus, we only unsubscribe from observables that are definitely not read anymore.
126
>
for (const o of this._dependenciesToBeRemoved) {
127
o.removeObserver(this); // Warning: external call!
128
}
130
>
}
131
>
}
132
133
public toString(): string {