getTab method

Future<ChromeTab?> getTab(
  1. bool accept(
    1. ChromeTab tab
    ), {
  2. Duration? retryFor,
})

Implementation

Future<ChromeTab?> getTab(
  bool Function(ChromeTab tab) accept, {
  Duration? retryFor,
}) async {
  var start = DateTime.now();
  var end = start;
  if (retryFor != null) {
    end = start.add(retryFor);
  }

  while (true) {
    try {
      for (var tab in await getTabs()) {
        if (accept(tab)) {
          return tab;
        }
      }
      if (end.isBefore(DateTime.now())) {
        return null;
      }
    } catch (e) {
      if (end.isBefore(DateTime.now())) {
        rethrow;
      }
    }
    await Future.delayed(const Duration(milliseconds: 25));
  }
}