Skip to content

Commit

Permalink
ensure last port in browser worker closes naturally with the outer sc…
Browse files Browse the repository at this point in the history
…ope (#4433)
  • Loading branch information
tim-smart authored Feb 11, 2025
1 parent b6a032f commit 3ffe06d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/green-socks-occur.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@effect/platform-browser": patch
---

ensure last port in browser worker closes naturally with the outer scope
11 changes: 6 additions & 5 deletions packages/platform-browser/src/internal/workerRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,14 @@ export const make = (self: MessagePort | Window) =>
FiberSet.unsafeAdd(fiberSet, fiber)
} else {
const port = ports.get(portId)
if (port) {
Effect.runFork(Scope.close(port[1], Exit.void))
if (!port) {
return
} else if (ports.size === 1) {
// let the last port close with the outer scope
return Deferred.unsafeDone(closeLatch, Exit.void)
}
ports.delete(portId)
if (ports.size === 0) {
Deferred.unsafeDone(closeLatch, Exit.void)
}
Effect.runFork(Scope.close(port[1], Exit.void))
}
}
}
Expand Down

0 comments on commit 3ffe06d

Please sign in to comment.