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

🚀 Feature Request: support FinalizationRegistry or other Weak references #2906

Open
Dexus opened this issue Oct 9, 2024 · 1 comment
Open

Comments

@Dexus
Copy link

Dexus commented Oct 9, 2024

Describe the solution

I am currently blocked because there are not many ways to fix my problem, I need FinalizationRegistry

  Uncaught ReferenceError: FinalizationRegistry is not defined
    at null.<anonymous>
  (file:///xxx/xxx/xxx/worker_api/node_modules/capnp-es/dist/index.mjs:991:32)
   [code: 10021]

ref: https://github.com/pi0/capnp-es - https://github.com/pi0/capnp-es/blob/main/src/rpc/conn.ts#L63

together with a current little patch:

diff --git a/node_modules/capnp-es/dist/shared/capnp-es.CM7jzxJY.d.mts b/node_modules/capnp-es/dist/shared/capnp-es.CM7jzxJY.d.mts
index f34cdca..0f60513 100644
--- a/node_modules/capnp-es/dist/shared/capnp-es.CM7jzxJY.d.mts
+++ b/node_modules/capnp-es/dist/shared/capnp-es.CM7jzxJY.d.mts
@@ -108,9 +108,9 @@ declare class List<T> extends Pointer implements Array<T> {
     toSpliced(start: number, deleteCount: number, ...items: T[]): T[];
     fill(value: T, start?: number, end?: number): this;
     copyWithin(target: number, start: number, end?: number): this;
-    keys(): IterableIterator<number>;
-    values(): IterableIterator<T>;
-    entries(): IterableIterator<[number, T]>;
+    keys(): ArrayIterator<number>;
+    values(): ArrayIterator<T>;
+    entries(): ArrayIterator<[number, T]>;
     flat<A, D extends number = 1>(this: A, depth?: D): FlatArray<A, D>[];
     with(index: number, value: T): T[];
     includes(_searchElement: T, _fromIndex?: number): boolean;
@@ -169,7 +169,7 @@ declare class List<T> extends Pointer implements Array<T> {
         [Symbol.iterator]?: boolean | undefined;
         readonly [Symbol.unscopables]?: boolean | undefined;
     };
-    [Symbol.iterator](): IterableIterator<T>;
+    [Symbol.iterator](): ArrayIterator<T>;
     toJSON(): unknown;
     toString(): string;
     toLocaleString(_locales?: unknown, _options?: unknown): string;

You using it self here: https://github.com/cloudflare/workers-sdk/blob/2e649686c259c639701a62e754c53448cb694dfc/packages/miniflare/src/plugins/core/proxy/client.ts#L141

and a related bug was reported here: cloudflare/workers-sdk#2258

@penalosa penalosa transferred this issue from cloudflare/workers-sdk Oct 11, 2024
@jasnell
Copy link
Member

jasnell commented Oct 11, 2024

It is unlikely that we will ever actually support FinalizationRegistry. I'm sure @kentonv can explain the reasoning best but the tl;dr is that we want to avoid making garbage collection timing observable. We don't currently support WeakRef but I've been thinking more and more than we probably could do so safely.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants