mayEmitMultiple function

StreamMatcher mayEmitMultiple (dynamic matcher)

Returns a StreamMatcher that matches any number of events that match matcher.

This consumes events until matcher no longer matches. It always succeeds; if matcher doesn't match, this just consumes no events. It never rethrows errors.

Implementation

StreamMatcher mayEmitMultiple(matcher) {
  var streamMatcher = emits(matcher);

  var description = streamMatcher.description;
  description += description.contains("\n") ? "\n" : " ";
  description += "zero or more times";

  return StreamMatcher((queue) async {
    while (await _tryMatch(queue, streamMatcher)) {
      // Do nothing; the matcher presumably already consumed events.
    }
    return null;
  }, description);
}