close method

Future<void> close({
  1. String message = 'Regular closing',
  2. Duration? timeout,
})

Sends a goodbye message and closes the transport after a given timeout. If no timeout is set, the client waits for the server to close the transport forever.

Implementation

Future<void> close({
  String message = 'Regular closing',
  Duration? timeout,
}) {
  if (_goodbyeSent) {
    return Future<void>.value();
  }
  _goodbyeSent = true;
  _transport.send(
    Goodbye(GoodbyeMessage(message), Goodbye.reasonNormal),
  );
  if (timeout != null) {
    return Future.delayed(timeout, () => _transport.close());
  }
  return Future<void>.value();
}