flush method
Completes once the socket's bufferedAmount is at most highWaterMark,
at once when it already is, polling for it otherwise.
Throws AtTimeoutException if it is not within flushTimeout, and
AtIOException if the socket closes first.
Implementation
@override
Future<void> flush() async {
final elapsed = Stopwatch()..start();
while (_port.bufferedAmount > _highWaterMark) {
if (_closed || !_port.isOpen) {
throw AtIOException(
'WebSocket to $description closed with ${_port.bufferedAmount} '
'bytes unsent');
}
if (elapsed.elapsed > _flushTimeout) {
throw AtTimeoutException(
'WebSocket to $description still had ${_port.bufferedAmount} '
'bytes unsent after $_flushTimeout');
}
await Future<void>.delayed(_flushPollInterval);
}
}