waitForValues method

Future<List<T>> waitForValues(
  1. int count, {
  2. Duration timeout = const Duration(seconds: 5),
})

Wait for a specific number of values.

Returns when at least count values have been received.

Implementation

Future<List<T>> waitForValues(
  int count, {
  Duration timeout = const Duration(seconds: 5),
}) async {
  final stopwatch = Stopwatch()..start();

  while (_values.length < count) {
    if (stopwatch.elapsed > timeout) {
      throw TimeoutException(
        'TestObserver timed out waiting for $count values. '
        'Received ${_values.length} values.',
        timeout,
      );
    }
    await Future.delayed(const Duration(milliseconds: 10));
  }

  return values;
}