firstWhere static method

Future<String> firstWhere(
  1. bool test(
    1. String element
    )
)

Implementation

static Future<String> firstWhere(bool Function(String element) test) {
  for (final e in currentApi!._calledEndpoints.entries) {
    if (e.value.isNotEmpty && test(e.key)) {
      return Future.value(e.key);
    }
  }

  final completer = Completer<String>();
  StreamSubscription<String>? sub;
  sub = currentApi!._apiCallStream.stream.listen((action) {
    if (test(action)) {
      sub?.cancel();
      completer.complete(action);
    }
  });
  return completer.future;
}