vmServiceOpened method

Future<void> vmServiceOpened(
  1. T service, {
  2. required Future<void> onClosed,
})

Initializes the service manager for a new vm service connection service.

Implementation

Future<void> vmServiceOpened(
  T service, {
  required Future<void> onClosed,
}) async {
  if (service == this.service) {
    // Service already opened.
    return;
  }
  this.service = service;
  serviceUri = service.wsUri!;

  if (_serviceAvailable.isCompleted) {
    _serviceAvailable = Completer();
  }

  connectedApp = ConnectedApp(this);

  // It is critical we call vmServiceOpened on each manager class before
  // performing any async operations. Otherwise, we may get end up with
  // race conditions where managers cannot listen for events soon enough.
  isolateManager.vmServiceOpened(service);
  serviceExtensionManager.vmServiceOpened(service, connectedApp!);
  resolvedUriManager.vmServiceOpened(service);

  await _configureIsolateSettings();

  await callLifecycleCallbacks(
    ServiceManagerLifecycle.beforeOpenVmService,
    service,
  );
  await _openVmServiceConnection(service, onClosed: onClosed);
  await callLifecycleCallbacks(
    ServiceManagerLifecycle.afterOpenVmService,
    service,
  );

  await connectedApp!.initializeValues();

  // This needs to be the last call in this method.
  _connectedState.value = const ConnectedState(true);
}