close method

Future<void> close()

Closes the WebSocket. Safe to call more than once.

Implementation

Future<void> close() async {
  if (_closed) return;
  _closed = true;
  try {
    await _sub?.cancel();
    await _channel?.sink.close();
  } catch (_) {}
  _channel = null;
  if (!_events.isClosed) await _events.close();
}