fetchStream method

Stream<T> fetchStream (Stream<T> callback())

Returns a cached stream from a previous call to fetchStream, or runs callback to compute a new stream.

If fetchStream has been called recently enough, returns a copy of its previous return value. Otherwise, runs callback and returns its new return value.


Stream<T> fetchStream(Stream<T> callback()) {
  if (_cachedValueFuture != null) {
    throw StateError('Previously used to cache via `fetch`');
  if (_cachedStreamSplitter == null) {
    _cachedStreamSplitter = StreamSplitter(callback()
        .transform(StreamTransformer.fromHandlers(handleDone: (sink) {
  return _cachedStreamSplitter.split();