writeText method

Future writeText(
  1. String text, [
  2. dynamic logObject
])
inherited

Writes the specified text.

When the log is enabled it will either log the specified logObject or just the text.

Implementation

Future writeText(String text, [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 ??= text;
    log(logObject);
  }
  _socket.write(text + '\r\n');
  final future = _socket.flush();
  _writeFuture = future;
  await future;
  _writeFuture = null;
}