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.

Implementation

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