diff --git a/packages/experimental/src/EventJournal.ts b/packages/experimental/src/EventJournal.ts index d0ad25635f1..8eb4e273ea3 100644 --- a/packages/experimental/src/EventJournal.ts +++ b/packages/experimental/src/EventJournal.ts @@ -274,7 +274,7 @@ export const makeMemory: Effect.Effect = Effect.gen const uncommittedRemotes: Array = [] const uncommitted: Array = [] for (const remoteEntry of options.entries) { - if (!byId.has(remoteEntry.entry.idString)) { + if (byId.has(remoteEntry.entry.idString)) { if (remoteEntry.remoteSequence > remote.sequence) { remote.sequence = remoteEntry.remoteSequence } diff --git a/packages/experimental/src/Reactivity.ts b/packages/experimental/src/Reactivity.ts index 333f8207de4..0da5072e5c2 100644 --- a/packages/experimental/src/Reactivity.ts +++ b/packages/experimental/src/Reactivity.ts @@ -72,17 +72,29 @@ export const make = Effect.sync(() => { const results = yield* Mailbox.make() const runFork = yield* FiberHandle.makeRuntime() - const handledEffect = Effect.matchCause(effect, { - onFailure(cause) { - results.unsafeDone(Exit.failCause(cause)) - }, - onSuccess(a) { - results.unsafeOffer(a) + let running = false + let pending = false + const handleExit = (exit: Exit.Exit) => { + if (exit._tag === "Failure") { + results.unsafeDone(Exit.failCause(exit.cause)) + } else { + results.unsafeOffer(exit.value) } - }) + if (pending) { + pending = false + run() + } else { + running = false + } + } function run() { - runFork(handledEffect, { onlyIfMissing: true }) + if (running) { + pending = true + return + } + running = true + runFork(effect).addObserver(handleExit) } yield* Scope.addFinalizer(