shouldReconnect
A predicate to decide whether the web socket should be reconnected when the given exception
occur. The attempt
parameter is the index of the current reconnection attempt in a series of retries.
When the web socket throws an exception, this predicate is called with attempt 0 before trying to reconnect. If the predicate returns false, the exception is rethrown and no reconnection is attempted. If the predicate returns true, a reconnection is attempted.
If the reconnection fails, the predicate is called again with attempt 1, and so on. If the reconnection succeeds, and later a new error occurs on the web socket, the predicate will be called again, with attempt 0.
The predicate will not be called if maxAttempts is reached. If you want to control the maximum attempts via the predicate, set maxAttempts to a bigger value (such as Int.MAX_VALUE).