neverEmits function

StreamMatcher neverEmits (
  1. dynamic matcher
)

Returns a StreamMatcher that matches a stream that never matches matcher.

This doesn't complete until the stream emits a done event. It never consumes any events. It never re-throws errors.

Implementation

StreamMatcher neverEmits(matcher) {
  var streamMatcher = emits(matcher);
  return StreamMatcher((queue) async {
    var events = 0;
    var matched = false;
    await queue.withTransaction((copy) async {
      while (await copy.hasNext) {
        matched = await _tryMatch(copy, streamMatcher);
        if (matched) return false;

        events++;

        try {
          await copy.next;
        } catch (_) {
          // Ignore errors events.
        }
      }

      matched = await _tryMatch(copy, streamMatcher);
      return false;
    });

    if (!matched) return null;
    return "after $events ${pluralize('event', events)} did "
        '${streamMatcher.description}';
  }, 'never ${streamMatcher.description}');
}