take method Null safety

Future<List<T>> take (
  1. int count
)

Requests the next count data events as a list.

The count must be non-negative.

Equivalent to calling next count times and storing the data values in a list.

If an error occurs before count data events has been collected, the returned future completes with that error instead.

If the stream closes before count data events, the returned future completes with the list of data collected so far. That is, the returned list may have fewer than count elements.

Implementation

Future<List<T>> take(int count) {
  if (count < 0) throw RangeError.range(count, 0, null, 'count');
  if (!_isClosed) {
    var request = _TakeRequest<T>(count);
    _addRequest(request);
    return request.future;
  }
  throw _failClosed();
}