Skip to content

[ECO-5658] Switch to using ably-swift's EventEmitter#131

Draft
lawrence-forooghian wants to merge 3 commits into
mainfrom
102-simplify-subscription-storage
Draft

[ECO-5658] Switch to using ably-swift's EventEmitter#131
lawrence-forooghian wants to merge 3 commits into
mainfrom
102-simplify-subscription-storage

Conversation

@lawrence-forooghian
Copy link
Copy Markdown
Collaborator

Removes the complicated updateSelfLater mutable state pattern and just wraps a EventEmitter class instead. No public API changes.

Resolves #102.

Copy EventEmitter.swift, InternalEventEmitter.swift,
DefaultInternalEventEmitter.swift and its tests from ably-swift
commit 98996f1, making the EventEmitter protocol internal.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 12, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: b3a388fe-312e-4d6b-aa0c-58f66d523a5b

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 102-simplify-subscription-storage

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

lawrence-forooghian and others added 2 commits May 12, 2026 09:43
The liveobjects plugin uses DispatchQueue-based concurrency, not
@mainactor. Adapt the EventEmitter (copied from ably-swift) to
match:

- Remove @mainactor from all protocols and classes
- Add Sendable conformance throughout
- Store mutable state in DispatchQueueMutex
- Prefix all methods with nosync_ (must be called on internal queue)
- Rename typealiases: MainActorEventListener → EventListener,
  MainActorNamedEventListener → NamedEventListener (now @sendable)
- SubscriptionController takes internalQueue in init, uses
  DispatchQueueMutex for its registrations
- DefaultInternalEventEmitter snapshots listeners inside withoutSync,
  calls them outside to avoid exclusivity violations on re-entry
- Update tests to use ably_syncNoDeadlock and nosync_ methods

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
SubscriptionStorage was a struct that manually managed subscription
bookkeeping. Because it was a value type, unsubscription required a
verbose updateSelfLater closure-threading pattern at every call site.

Replace it with a class wrapping DefaultInternalEventEmitter. A
private EmitData struct bundles the update with the dispatch queue so
nosync_emit can still accept a queue parameter. Each
nosync_subscribe creates a SubscriptionController whose signal is
passed to the emitter; the returned SubscribeResponse captures the
controller and synchronously dispatches nosync_off() on unsubscribe.

Because SubscriptionStorage is now a reference type, the
updateSelfLater closures throughout LiveObjectMutableState,
InternalDefaultLiveCounter, InternalDefaultLiveMap, and
InternalDefaultRealtimeObjects are no longer needed and are removed.
The subscription/emit methods on LiveObjectMutableState drop their
mutating qualifier and gain a nosync_ prefix for consistency.

TODO: Lawrence check that this resolves #102
TODO: There's still a mention of updateSelfLater

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Switch to something simpler for subscription storage

1 participant