dispose method
Disposes the client, closes all subscriptions, and disconnects the underlying WebSocket connection.
Implementation
Future<void> dispose() async {
_disposed = true;
_reconnectTimer?.cancel();
await _connectionEventSubscription.cancel();
await _messageSubscription.cancel();
await _socketErrorSubscription.cancel();
_failPendingEmits(
StateError('MongoRealtime was disposed before emit completed.'),
);
await _queryManager.dispose();
_cacheManager.clear();
await _webSocketService.dispose();
if (identical(_instance, this)) {
_instance = null;
}
}