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
Copy file name to clipboardExpand all lines: docs/client-configuration.md
+7-18Lines changed: 7 additions & 18 deletions
Original file line number
Diff line number
Diff line change
@@ -29,28 +29,17 @@
29
29
30
30
## Reconnect Strategy
31
31
32
-
TODO: `false | number | (retries: number, cause: unknown) => number | Error`
32
+
When the socket closes unexpectedly (without calling `.quit()`/`.disconnect()`) the client uses `reconnectStrategy` to decide what to do:
33
+
1.`false` -> do not reconnect, close the client and flush all commands in the queue.
34
+
2.`number` -> wait for `X` milliseconds before reconnecting.
35
+
3.`(retries: number, cause: Error) => number | Error` -> `number` is the same as configuration a `number` directly, `Error` is the same as `false`, but with a custom error.
33
36
34
-
You can implement a custom reconnect strategy as a function:
35
-
When a network error occurs the client will automatically try to reconnect, following a default linear strategy (the more attempts, the more waiting before trying to reconnect).
36
-
37
-
This strategy can be overridden by providing a `socket.reconnectStrategy` option during the client's creation.
38
-
39
-
The `socket.reconnectStrategy` is a function that:
40
-
41
-
- Receives the number of retries attempted so far and the causing error.
42
-
- Returns `number | Error`:
43
-
-`number`: wait time in milliseconds prior to attempting a reconnect.
44
-
-`Error`: closes the client and flushes internal command queues.
45
-
46
-
The example below shows the default `reconnectStrategy` and how to override it.
37
+
By default the strategy is `Math.min(retries * 50, 500)`, but it can be overriten:
0 commit comments