fetchStream method

  1. @Deprecated('Feature will be removed')
Stream<T> fetchStream(
  1. 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.

Each call to this function returns a stream which replays the same events, which means that all stream events are cached until this cache is invalidated.

Only starts counting time after the stream has been listened to, and it has completed with a done event.

Implementation

@Deprecated('Feature will be removed')
Stream<T> fetchStream(Stream<T> Function() callback) {
  if (_cachedValueFuture != null) {
    throw StateError('Previously used to cache via `fetch`');
  }
  var splitter = _cachedStreamSplitter ??= StreamSplitter(
      callback().transform(StreamTransformer.fromHandlers(handleDone: (sink) {
    _startStaleTimer();
    sink.close();
  })));
  return splitter.split();
}