writeText method
Writes the specified text
.
When the log is enabled it will either log the specified logObject
or just the text
.
When a timeout
is specified and occurs, it will
throw a TimeoutException after the specified time.
Implementation
Future writeText(String text, [dynamic logObject, Duration? timeout]) async {
final previousWriteFuture = _writeFuture;
if (previousWriteFuture != null) {
try {
await previousWriteFuture;
} catch (e, s) {
print('Unable to await previous write '
// ignore: unawaited_futures
'future $previousWriteFuture: $e $s');
_writeFuture = null;
rethrow;
}
}
if (isLogEnabled) {
logObject ??= text;
log(logObject);
}
_socket.write('$text\r\n');
final future =
timeout == null ? _socket.flush() : _socket.flush().timeout(timeout);
_writeFuture = future;
await future;
_writeFuture = null;
}