Skip to content

Reinitiate reconnect after manually connect #4075

Discussion options

You must be logged in to vote

To answer my own question (been struggeling with this for hours yesterday), I've added a timeout on the finally of the promise (because no matter if there's an error or not, I want the reconnect to again after trying), which triggers the socket.connect, like this:

await new Promise<void>((resolve, reject) => {
  socket.io.connect((err) => {
    if (err) {
      return resolve(new Error('Could not connect to socket');
    }
    return resolve();
  });
}).finally(() => setTimeout(() => socket.connect(), 200));

It seems like that does the trick. Directly invoking socket.connect doesn't work, but with a small timeout it does. Don't know if this is expected behaviour, but for now it does the j…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by bartversluijs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant