connectDtdImpl method

  1. @visibleForTesting
Future<DartToolingDaemon> connectDtdImpl(
  1. Uri uri
)

A wrapper around connecting to DTD to allow tests to intercept the connection.

Implementation

@visibleForTesting
Future<DartToolingDaemon> connectDtdImpl(Uri uri) async {
  // Cancel any previous timer.
  _periodicConnectionCheck?.cancel();

  final dtd = await DartToolingDaemon.connect(uri);

  // Set up a periodic connection check to detect if the connection has
  // dropped even if `done` doesn't fire.
  //
  // If this happens, just disconnect (without disabling reconnect) so the
  // done event fires and then the usual handling occurs.
  _periodicConnectionCheck =
      Timer.periodic(_periodicConnectionCheckInterval, (timer) async {
    if (_dtd.isClosed) {
      _log.warning('The DTD connection has dropped');
      await disconnectImpl(allowReconnect: true);
    }
  });

  return dtd;
}