connect<T extends VmService> function
Future<T>
connect<
T extends VmService>({ - required Uri uri,
- required Completer<void> finishedCompleter,
- required VmServiceFactory<T> serviceFactory,
})
Implementation
Future<T> connect<T extends VmService>({
required Uri uri,
required Completer<void> finishedCompleter,
required VmServiceFactory<T> serviceFactory,
}) {
final connectedCompleter = Completer<T>();
void onError(Object? error) => connectedCompleter.safeCompleteError(error!);
Future<T> connectHelper() async {
final useSse = uri.scheme == 'sse' || uri.scheme == 'sses';
final T service = useSse
? await _connectWithSse<T>(
uri: uri,
onError: onError,
finishedCompleter: finishedCompleter,
serviceFactory: serviceFactory,
)
: await _connectWithWebSocket<T>(
uri: uri,
onError: onError,
finishedCompleter: finishedCompleter,
serviceFactory: serviceFactory,
);
await service.getVersion();
return service;
}
connectHelper().then(
(service) => connectedCompleter.safeComplete(service),
onError: onError,
);
finishedCompleter.future.then((_) {
if (!connectedCompleter.isCompleted) {
onError(null);
}
});
return connectedCompleter.future;
}