disconnect method

Future<NetworkPrintResult> disconnect({
  1. Duration? timeout,
})

Disconnect with proper resource cleanup

Implementation

Future<NetworkPrintResult> disconnect({Duration? timeout}) async {
  try {
    if (_socket != null) {
      await _socket!.flush();
      await _socket!.close();
      _socket = null;
    }
    _isConnected = false;

    if (timeout != null) {
      await Future.delayed(timeout);
    }

    return NetworkPrintResult.success;
  } catch (e) {
    _isConnected = false;
    _socket = null;
    return NetworkPrintResult.success; // Still consider it successful cleanup
  }
}