stop method
Stops the connection.
Returns a Promise that resolves when the connection has been successfully terminated, or rejects with an error.
Implementation
Future<void> stop() async {
// Capture the start promise before the connection might be restarted in an onclose callback.
final startPromise = _startPromise;
_stopPromise = _stopInternal();
await _stopPromise;
try {
// Awaiting undefined continues immediately
await startPromise;
} catch (e) {
// This exception is returned to the user as a rejected Promise from the start method.
}
}