Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use Map for Scope finalizers, to ensure they are always added #4431

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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