connect method

Future<void> connect()

Implementation

Future<void> connect() async {
  if (connectionState != PipeConnectionState.disconnected) {
    _logger.warning(
      'Tried to connect to the pipe while connection is already opened.',
    );
    return;
  }

  try {
    _hubConnection
      ..onreconnected((connectionId) async {
        await Future.wait([
          for (final topicSub in _registeredTopicSubscriptions)
            _reconnect(topicSub),
        ]);
        onReconnected?.call();
      })
      ..onreconnecting((error) {
        onReconnecting?.call(error);
      })
      ..onclose((error) async {
        await Future.wait([
          for (final topicSub in _registeredTopicSubscriptions)
            topicSub.close(),
        ]);
        _registeredTopicSubscriptions.clear();
        onClose?.call(error);
      })
      ..on('subscriptionResult', _onSubscriptionResult)
      ..on('notify', _onNotify);
    await _hubConnection.start();
  } catch (err, st) {
    _logger.shout('Could not connect to LeanCode pipe service', err, st);
    throw const PipeConnectionException();
  }
}