Skip to content

Commit

Permalink
Cleanup signal "abort" event handler in Micro.runFork (#3067)
Browse files Browse the repository at this point in the history
Co-authored-by: maksim.khramtsov <maksim.khramtsov@btsdigital.kz>
Co-authored-by: Tim <hello@timsmart.co>
  • Loading branch information
3 people authored Jun 25, 2024
1 parent 81027a1 commit 8898e5e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/eight-points-push.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": patch
---

Cleanup signal "abort" event handler in `Micro.runFork`
5 changes: 4 additions & 1 deletion packages/effect/src/Micro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3672,12 +3672,15 @@ export const runFork = <A, E>(
const handle = new HandleImpl<A, E>(controller.signal, controller)
effect[runSymbol](envSet(env, currentAbortSignal, handle._controller.signal), (result) => {
handle.emit(result)
if (options?.signal) {
options.signal.removeEventListener("abort", handle.unsafeAbort)
}
})
if (options?.signal) {
if (options.signal.aborted) {
handle.unsafeAbort()
} else {
options.signal.addEventListener("abort", () => handle.unsafeAbort())
options.signal.addEventListener("abort", handle.unsafeAbort, { once: true })
}
}
return handle
Expand Down

0 comments on commit 8898e5e

Please sign in to comment.