connect static method

Future<ServerAttachClient> connect(
  1. ServerHandle handle, {
  2. Duration timeout = const Duration(seconds: 2),
})

Connects and attaches, or throws — on refused connect, on timeout, on a hello that never comes. The caller decides whether a failure means "delete the handle" (attachToServer does).

Implementation

static Future<ServerAttachClient> connect(
  ServerHandle handle, {
  Duration timeout = const Duration(seconds: 2),
}) async {
  // Closed by [close] / [_onClosed]; the analyzer cannot follow the handoff.
  // ignore: close_sinks
  var socket = await Socket.connect(
    InternetAddress(handle.socketPath, type: InternetAddressType.unix),
    0,
  ).timeout(timeout);
  var client = ServerAttachClient._(handle, socket);
  try {
    client._hello = await client._session
        .attach()
        .then(_decodeHello)
        .timeout(timeout);
    return client;
  } on Object {
    await client.close();
    rethrow;
  }
}