untilCalled top-level property

Future<Invocation> Function<T>(T _()) untilCalled

Returns a future Invocation that will complete upon the first occurrence of the given invocation.

Usage of this is as follows:

cat.eatFood("fish");
await untilCalled(cat.chew());

In the above example, the untilCalled(cat.chew()) will complete only when that method is called. If the given invocation has already been called, the future will return immediately.

Implementation

Future<Invocation> Function<T>(T Function() _) get untilCalled {
  _untilCalledInProgress = true;
  return <T>(T Function() _) {
    try {
      _();
    } catch (_) {
      if (_ is! TypeError) rethrow;
    }
    _untilCalledInProgress = false;
    return _untilCall!.invocationFuture;
  };
}