-
Notifications
You must be signed in to change notification settings - Fork 16
Description
Hi, i currently listen to balance changes like this:
const balanceWsClient = new WsClient({
url: wsUrl,
maxReconnectAttempts: 10 * 60 * 1000,
reconnectInterval: 1,
onOpen: () => {
// Subscribe, etcAnd my reconnectInterval of 1ms is obviously very tight, but i need the Websockets to get back up as soon as possible always.
The 1 ms is fine most of the cases and dthe WS reconnects most of the times as expected, but every once in a while it doesn't, so the program exits.
My proposal would be to add another optional parameter to the WsClient, named e.g. reconnectBackoffStrategy or something, whcih takes a function definition it uses to calculate the delay until the next reconnect.
e.g. passing it like this
const balanceWsClient = new WsClient({
url: wsUrl,
maxReconnectAttempts: 10 * 60 * 1000,
reconnectInterval: 1,
reconnectBackoffStrategy: reconnectPolicy,
onOpen: () => {
// Subscribe, etcwith the function definition like this:
const reconnectPolicy = (currentDelay) => {
return currentDelay * 2;
};This would allow e.g. an exponential backoff, so the websocket does not retry every e.g. 1ms in my case, but like this:
1ms -> 2ms -> 4ms -> ... -> 1073741824ms