Skip to content

feat: add IterableWeakSet and IterableWeakMap classes#19

Open
handsomesix wants to merge 2 commits into
bogeeee:mainfrom
handsomesix:feat/iterable-weak
Open

feat: add IterableWeakSet and IterableWeakMap classes#19
handsomesix wants to merge 2 commits into
bogeeee:mainfrom
handsomesix:feat/iterable-weak

Conversation

@handsomesix

Copy link
Copy Markdown

Implements IterableWeakSet<T> and IterableWeakMap<K, V> using WeakRef + FinalizationRegistry. Closes #9.

Hermes Agent added 2 commits June 12, 2026 01:11
This addresses issue bogeeee#8: withTrim no longer creates a new function
instance on every call. Instead, it reuses the same wrapper for
identical (callbackFn, useSignatureFrom) pairs, enabling use with
addEventListener/removeEventListener patterns.
- WeakMap cache per callbackFn with auto-GC
- Inner Map tracks useSignatureFrom variants
Implements iterable weak collection types using WeakRef + FinalizationRegistry,
enabling safe cleanup of connection-bound callbacks without memory leaks.

These classes solve the issue where ClientCallbacks/ClientCallbacksForEntities
need to be forgettable but also iterable - something the built-in WeakSet/WeakMap
don't support and the not-so-weak package's implementation has correctness bugs.

Implementation details:
- Uses WeakRef to hold weak references to values/keys
- Uses FinalizationRegistry to detect when entries are GC'd
- Automatically compacts internal storage during iteration
- Fully typed with proper TypeScript generics
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

Successfully merging this pull request may close these issues.

Implement IterableWeakSet IterableWeakMap classes

1 participant