Skip to content

Commit

Permalink
fix: wait in recursive connect
Browse files Browse the repository at this point in the history
  • Loading branch information
enisdenjo committed Dec 9, 2020
1 parent bbb0daa commit b6b9c6b
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,28 +290,28 @@ export function createClient(options: ClientOptions): Client {
}
}

// if recursive call, wait a bit for socket change
await new Promise((resolve) => setTimeout(resolve, callDepth * 50));

// socket already exists. can be ready or pending, check and behave accordingly
if (state.socket) {
switch (state.socket.readyState) {
case WebSocketImpl.OPEN: {
// if the socket is not acknowledged, wait a bit and reavaluate
if (!state.acknowledged) {
await new Promise((resolve) => setTimeout(resolve, 300));
return connect(cancellerRef, callDepth + 1);
}

return makeConnectReturn(state.socket, cancellerRef);
}
case WebSocketImpl.CONNECTING: {
// if the socket is in the connecting phase, wait a bit and reavaluate
await new Promise((resolve) => setTimeout(resolve, 300));
return connect(cancellerRef, callDepth + 1);
}
case WebSocketImpl.CLOSED:
break; // just continue, we'll make a new one
case WebSocketImpl.CLOSING: {
// if the socket is in the closing phase, wait a bit and connect
await new Promise((resolve) => setTimeout(resolve, 300));
return connect(cancellerRef, callDepth + 1);
}
default:
Expand Down

0 comments on commit b6b9c6b

Please sign in to comment.