Skip to content

Commit 292db28

Browse files
committed
Stabilize computed that calls set
1 parent d39e2b4 commit 292db28

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

src/graph.ts

+16-6
Original file line numberDiff line numberDiff line change
@@ -236,14 +236,24 @@ export class ComputedNode<T> extends SignalNode<T | ComputedSpecialValues> imple
236236
this.computing = true;
237237
let value: T | ComputedSpecialValues;
238238
const prevActiveConsumer = setActiveConsumer(this);
239-
try {
240-
value = this.computeFn.call(this.wrapper);
241-
} catch (error) {
242-
value = COMPUTED_ERRORED;
243-
this.error = error;
239+
let isUpToDate = false;
240+
let iterations = 0;
241+
while (!isUpToDate && iterations < 1000) {
242+
try {
243+
value = this.computeFn.call(this.wrapper);
244+
} catch (error) {
245+
value = COMPUTED_ERRORED;
246+
this.error = error;
247+
}
248+
this.#removeUnusedProducers();
249+
iterations++;
250+
isUpToDate = this.#areProducersUpToDate();
244251
}
245-
this.#removeUnusedProducers();
246252
setActiveConsumer(prevActiveConsumer);
253+
if (!isUpToDate) {
254+
value = COMPUTED_ERRORED;
255+
this.error = new Error('Could not stabilize the computation.');
256+
}
247257
this.computing = false;
248258
this.dirty = false;
249259
this.set(value, false);

0 commit comments

Comments
 (0)