More testing and cleaning up

This commit is contained in:
Timo K
2025-11-27 14:42:23 +01:00
parent d22d7460fe
commit e5117f705d
4 changed files with 321 additions and 127 deletions

View File

@@ -80,8 +80,11 @@ export class ObservableScope {
error(err: unknown) {
subject$.error(err);
},
complete() {
subject$.complete();
},
});
if (subject$.value === nothing)
if (subject$.value === nothing && !subject$.isStopped)
throw new Error("Behavior failed to synchronously emit an initial value");
return subject$ as Behavior<T>;
}
@@ -125,11 +128,11 @@ export class ObservableScope {
let latestValue: T | typeof nothing = nothing;
let reconcilePromise: Promise<void> | undefined = undefined;
let cleanUp: (() => Promise<void>) | void = undefined;
let prevVal: T | typeof nothing = nothing;
// While this loop runs it will process the latest from `value$` until it caught up with the updates.
// It might skip updates from `value$` and only process the newest value after callback has resolved.
const reconcileLoop = async (): Promise<void> => {
let prevVal: T | typeof nothing = nothing;
while (latestValue !== prevVal) {
await cleanUp?.(); // Call the previous value's clean-up handler
prevVal = latestValue;