close method

  1. @override
Future<void> close()
override

Close the channel and release resources.

Asymmetric, and the CLOSING side is the one that loses. What this side had already queued is still delivered; what the peer had queued toward us is dropped, because closing cancels the inbound subscription. Measured with both ends queuing a frame in the same turn and the client closing: the client received [] / the server received [from-client], mirrored when the server closes.

Kept deliberately rather than fixed. Delivering that queued inbound needs an event-loop turn before the cancel, and the turn delays the close CASCADE — the peer's onDone, its channel, its transport — so a peer's sendMessage right after await close() stopped throwing and started succeeding silently. Of the two losses that is the worse one. A side that wants the peer's last frames must read them before closing.

Implementation

@override
Future<void> close() async {
  if (_closed) return;
  _closed = true;

  await _channelSub?.cancel();
  _channelSub = null;

  try {
    await _channel.close();
  } catch (_) {}

  await _releaseAfterChannelClose();
}