Skip to content

Conversation

@JulianVennen
Copy link
Member

Supersedes #13

Schedule reconnects using setTimeout instead of setInterval

This prevents multiple reconnect intervals from existing at the same time.

Prevent multiple subscribe calls from trying to start concurrent connection attempts

When calling subscribe multiple times while the connection hasn't been established yet, the websocket would call the connect method multiple times. e.g.:

server.subscribe();
server.subscribe("console");
server.subscribe("heap");

Each of these would call isConnected() and call the connect method again, because onOpen hasn't been reached yet.
isConnected() generally doesn't check if the connection is open in this exact moment, but rather if the connection is generally trying to be connected. If a reconnect is attempted, onClose doesn't set this property to false, but it's only set to true once onOpen is called.
This PR changes that to make isConnected return true from the first connect() call until the connection closes without a reconnect attempt.

Arguably, this is almost the same as #shouldConnect and we could consider making a getter for that instead.

@JulianVennen JulianVennen merged commit 273a5c5 into master Nov 29, 2025
@JulianVennen JulianVennen deleted the ws branch November 29, 2025 14:21
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.

3 participants