onTimerElapsed method

  1. @visibleForTesting
Future<void> onTimerElapsed()

Called when the backoff expired

Implementation

@visibleForTesting
Future<void> onTimerElapsed() async {
  _log.finest('Timer elapsed. Waiting for lock...');
  final shouldContinue = await _timerLock.synchronized(() async {
    _log.finest('Timer lock aquired');
    if (_timer == null) {
      _log.finest(
        'The timer is already set to null. Doing nothing.',
      );
      return false;
    }

    if (!(await getIsReconnecting())) {
      return false;
    }

    if (!(await getShouldReconnect())) {
      _log.finest(
        'Should not reconnect. Stopping here.',
      );
      return false;
    }

    _timer?.cancel();
    _timer = null;
    return true;
  });

  if (!shouldContinue) {
    return;
  }

  _log.fine('Triggering reconnect');
  await performReconnect!();
}