collectStream<R, T> function

Future<List<T>> collectStream<R, T>(
  1. Stream<R> stream, {
  2. required List<T> extract(
    1. R response
    ),
  3. int maxPages = 10,
})

Collects items from a paginated server stream with a maximum page cap to prevent unbounded memory growth.

stream is the gRPC response stream. extract pulls the list of items from each response message. maxPages limits how many pages are consumed (default 10). Returns the accumulated list.

Implementation

Future<List<T>> collectStream<R, T>(
  Stream<R> stream, {
  required List<T> Function(R response) extract,
  int maxPages = 10,
}) async {
  final result = await collectStreamPaged(
    stream,
    extract: extract,
    maxPages: maxPages,
  );
  return result.items;
}