close method

Future<void> close()

Disconnects, waiting at most closeBound. Idempotent.

Bounded, because the wait is not ours to finish. Socket.close completes through a continuation queued in the zone the socket was last written in, and — measured — when that zone never runs again the close never returns. In the product that zone is the root zone and it always runs; in a widget test it is the fake-async zone the completion ran in, which nothing pumps once the test body has finished, and a far end that stops reading (a frozen editor window) stalls it the same way. The standalone transport kills its child after this returns, so an unbounded wait here also kept its SIGKILL backstop from ever running. Past the bound the socket is left to finish on its own; a disposal is not the place to wait on a peer.

Implementation

Future<void> close() async {
  if (client.isConnected) {
    await client.disconnect().timeout(closeBound, onTimeout: () {});
  }
}