Skip to content

Commit

Permalink
Merge branch 'next-minor' into cron-tz
Browse files Browse the repository at this point in the history
  • Loading branch information
fubhy authored Dec 10, 2024
2 parents bc2027c + 418290a commit 96b3999
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/gentle-islands-invent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@effect/experimental": patch
---

ensure Reactivity events aren't missed
30 changes: 20 additions & 10 deletions packages/experimental/src/Reactivity.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**
* @since 1.0.0
*/
import * as Cause from "effect/Cause"
import * as Context from "effect/Context"
import * as Effect from "effect/Effect"
import * as Exit from "effect/Exit"
Expand Down Expand Up @@ -73,18 +72,29 @@ export const make = Effect.sync(() => {
const results = yield* Mailbox.make<A, E>()
const runFork = yield* FiberHandle.makeRuntime<R>()

const handledEffect = Effect.matchCause(effect, {
onFailure(cause) {
if (Cause.isInterruptedOnly(cause)) return
results.unsafeDone(Exit.failCause(cause))
},
onSuccess(a) {
results.unsafeOffer(a)
let running = false
let pending = false
const handleExit = (exit: Exit.Exit<A, E>) => {
if (exit._tag === "Failure") {
results.unsafeDone(Exit.failCause(exit.cause))
} else {
results.unsafeOffer(exit.value)
}
})
if (pending) {
pending = false
runFork(effect).addObserver(handleExit)
} else {
running = false
}
}

function run() {
runFork(handledEffect)
if (running) {
pending = true
return
}
running = true
runFork(effect).addObserver(handleExit)
}

yield* Scope.addFinalizer(
Expand Down

0 comments on commit 96b3999

Please sign in to comment.