waitFor<T> method

Future<T> waitFor<T>(
  1. FutureOr<T> condition(
    1. {Object? matcher,
    2. Duration timeout = defaultTimeout,
    3. Duration interval = defaultInterval}

    Waits until condition evaluates to a value that matches matcher or until timeout time has passed. If condition returns a Future, then uses the value of that Future rather than the value of condition.

    If the wait is successful, then the matching return value of condition is returned. Otherwise, if condition throws, then that exception is rethrown. If condition doesn't throw then an expect exception is thrown.


    Future<T> waitFor<T>(FutureOr<T> Function() condition,
        {Object? matcher,
        Duration timeout = defaultTimeout,
        Duration interval = defaultInterval}) async {
      final mMatcher = matcher == null ? null : m.wrapMatcher(matcher);
      final endTime = now.add(timeout);
      while (true) {
        try {
          final value = await condition();
          if (mMatcher != null) {
            _matcherExpect(value, mMatcher);
          return value;
        } catch (e) {
          if (now.isAfter(endTime)) {
          } else {
            await sleep(interval);