disconnect method

  1. @override
Future disconnect({
  1. Duration? timeout,
})
override

disconnect flushes pending data and closes the socket.

timeout — optional delay after closing (useful for printers that need time to finish processing before a reconnect).

Implementation

@override
Future disconnect({Duration? timeout}) async {
  try {
    await socket?.flush();
    await socket?.close();
  } catch (_) {
    // Ignore errors during cleanup.
  } finally {
    socket = null;
  }

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