mayEmitMultiple method

  1. @awaitNotRequired
Future<void> mayEmitMultiple(
  1. AsyncCondition<T> condition
)

Optionally consumes events that match condition from the stream.

This expectation never fails.

Consumes matching events until one of the following happens:

  • A non-matching event is emitted.
  • An error is emitted.
  • The stream closes.

Implementation

@awaitNotRequired
Future<void> mayEmitMultiple(AsyncCondition<T> condition) {
  return context.expectAsync(
    () {
      try {
        return ['may emit a value that:', ...describe(condition)];
      } on AsyncConditionDisallowed {
        return ['may emit a value satisfying an asynchronous condition'];
      }
    },
    (actual) async {
      while (await actual.hasNext) {
        try {
          final value = await actual.peek;
          if (await softCheckAsync(value, condition) == null) {
            await actual.next;
          } else {
            return null;
          }
        } catch (_) {
          return null;
        }
      }
      return null;
    },
  );
}