waitForServiceExtensionAvailable method

Future<bool> waitForServiceExtensionAvailable(
  1. String name
)

Implementation

Future<bool> waitForServiceExtensionAvailable(String name) {
  if (isServiceExtensionAvailable(name)) return Future.value(true);

  Completer<bool> createCompleter() {
    // Listen for when the service extension is added and use it.
    final completer = Completer<bool>();
    final listenable = hasServiceExtension(name);
    late VoidCallback listener;
    listener = () {
      if (listenable.value || !completer.isCompleted) {
        listenable.removeListener(listener);
        completer.complete(true);
      }
    };
    hasServiceExtension(name).addListener(listener);
    return completer;
  }

  _maybeRegisteringServiceExtensions[name] ??= createCompleter();
  return _maybeRegisteringServiceExtensions[name]!.future;
}