fetchStream method

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.

    Implementation

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