You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to create a state machine which connects to and maintains a WebSocket connection with a sever. For this I have an external service which connects and handles the WebSocket connection and which returns a promise. I use this method to create a promise actor (in XState v5) to establish connection with the server.
However, the goal is for the client to reestablish connection if it gets disconnected from the server. I have something like this so far:
Without the state OtherStateWhereSocketConnectionShouldBeMaintained connection/disconnection is handled as expected. However once the connection is established the first time and the current state is OtherStateWhereSocketConnectionShouldBeMaintained.NetworkConnectivityStatus.Connected, and a disconnect event is fired (from within the ConnectToServer function. The promise actor which was first invoked still remains in the background resulting in two concurrent connections to the server, which is not what I need.
What's the best way to handle this? I've tried stopping the promise actor but the documentation doesn't give a lot of examples. Calling stopChild('ConnectToServer') on DISCONNECT events didn't work.
Appreciate any help I can get to get this working.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I am trying to create a state machine which connects to and maintains a WebSocket connection with a sever. For this I have an external service which connects and handles the WebSocket connection and which returns a promise. I use this method to create a promise actor (in XState v5) to establish connection with the server.
However, the goal is for the client to reestablish connection if it gets disconnected from the server. I have something like this so far:
Without the state
OtherStateWhereSocketConnectionShouldBeMaintained
connection/disconnection is handled as expected. However once the connection is established the first time and the current state is OtherStateWhereSocketConnectionShouldBeMaintained.NetworkConnectivityStatus.Connected, and a disconnect event is fired (from within the ConnectToServer function. The promise actor which was first invoked still remains in the background resulting in two concurrent connections to the server, which is not what I need.What's the best way to handle this? I've tried stopping the promise actor but the documentation doesn't give a lot of examples. Calling
stopChild('ConnectToServer')
on DISCONNECT events didn't work.Appreciate any help I can get to get this working.
Beta Was this translation helpful? Give feedback.
All reactions