Skip to content

Commit f99eae7

Browse files
committed
Add finalizer symbol
1 parent 30e5b8c commit f99eae7

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/comlink.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export { Endpoint };
2525
export const proxyMarker = Symbol("Comlink.proxy");
2626
export const createEndpoint = Symbol("Comlink.endpoint");
2727
export const releaseProxy = Symbol("Comlink.releaseProxy");
28+
export const finalizer = Symbol("Comlink.finalizer");
2829

2930
const throwMarker = Symbol("Comlink.thrown");
3031

@@ -345,6 +346,9 @@ export function expose(obj: any, ep: Endpoint = self as any) {
345346
// detach and deactive after sending release response above.
346347
ep.removeEventListener("message", callback as any);
347348
closeEndPoint(ep);
349+
if (finalizer in obj && typeof obj[finalizer] === "function") {
350+
obj[finalizer]();
351+
}
348352
}
349353
});
350354
} as any);
@@ -387,7 +391,7 @@ declare var FinalizationRegistry: FinalizationRegistry<Endpoint>;
387391

388392
const proxyCounter = new WeakMap<Endpoint, number>();
389393
const proxyFinalizers =
390-
"FinalizationRegstry" in self &&
394+
"FinalizationRegistry" in self &&
391395
new FinalizationRegistry((ep: Endpoint) => {
392396
const newCount = (proxyCounter.get(ep) || 0) - 1;
393397
proxyCounter.set(ep, newCount);

0 commit comments

Comments
 (0)