read method

Future<List<T>> read (int size)

Read fully size bytes from the stream and return in the future.

Throws ArgumentError if size is larger than optional buffer limit.

Implementation

Future<List<T>> read(int size) {
  if (limited && size > limit) {
    throw new ArgumentError("Cannot read $size with limit $limit");
  }

  // If we have enough data to consume and there are no other readers, then
  // we can return immediately.
  if (size <= buffered && _readers.isEmpty) {
    return new Future.value(_consume(size));
  }
  final completer = new Completer<List<T>>();
  _readers.add(new _ReaderInWaiting<List<T>>(size, completer));
  return completer.future;
}