flush method
Completes once everything sent so far has left this process: handed
to the network, nothing of it waiting in memory any more. So a loop
that awaits it after each sendMessage sends as fast as the other
side reads, and never reaches the session's sendBufferSizeLimit.
Fails with a WebSocketException when the connection closes, breaks
or is dropped first (past sendTimeLimit, for example). On a session
made with the IoWebSocketSession.new constructor it completes at
once: dart:io does not tell.
Spring (Java): sendMessage itself blocks until the message is sent.
Implementation
Future<void> flush() async {
final guard = _guard;
if (guard == null) {
return;
}
try {
await guard.flushed();
} on StateError catch (error) {
throw WebSocketException(error.message, url: uri, cause: error);
}
}