writeData method Null safety

Future writeData(
  1. List<int> data,
  2. [dynamic logObject]
)
inherited

Writes the specified data.

When the log is enabled it will either log the specified logObject or just the length of the data.

Implementation

Future writeData(List<int> data, [dynamic logObject]) async {
  final previousWriteFuture = _writeFuture;
  if (previousWriteFuture != null) {
    try {
      await previousWriteFuture;
    } catch (e, s) {
      print('Unable to await previous write future: $e $s');
      _writeFuture = null;
    }
  }
  if (isLogEnabled) {
    logObject ??= '<${data.length} bytes>';
    log(logObject);
  }
  _socket.add(data);
  final future = _socket.flush();
  _writeFuture = future;
  await future;
  _writeFuture = null;
}