Skip to content

Commit

Permalink
fix(client): Reintroduce global emitter (#1192)
Browse files Browse the repository at this point in the history
See #1191 for description
of issues that arose from removing the global emitter.

I'm opening this PR in the case we decide that we want to reintroduce it
as it ensures that all instantiated electric clients will share
notifications between them.
  • Loading branch information
msfstef committed Apr 25, 2024
1 parent 6573147 commit dd5bd65
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .changeset/grumpy-years-cheer.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"electric-sql": patch
---

Remove global `EventEmitter` and remove max listener warning.
Remove max listener warning on `EventNotifier`'s event emitter.
13 changes: 7 additions & 6 deletions clients/typescript/src/notifiers/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ export const EVENT_NAMES = {
connectivityStateChange: 'network:connectivity:changed',
}

// Initialise global emitter to be shared between all
// electric instances (unless emitter is passed in)
// Remove warning as we don't want to limit the number
// of subscribers
const globalEmitter = new EventEmitter().setMaxListeners(Infinity)

export class EventNotifier implements Notifier {
dbName: DbName

Expand All @@ -50,12 +56,7 @@ export class EventNotifier implements Notifier {
byName: {},
}

this.events =
eventEmitter !== undefined
? eventEmitter
: // initialise emitter with no limit to listeners as
// we don't want to limit the number of subscribers
new EventEmitter().setMaxListeners(Infinity)
this.events = eventEmitter !== undefined ? eventEmitter : globalEmitter
}

attach(dbName: DbName, dbAlias: string): void {
Expand Down

0 comments on commit dd5bd65

Please sign in to comment.