fetch method

Future<T> fetch (
  1. Future<T> callback(
      )
    )

    Returns a cached value from a previous call to fetch, or runs callback to compute a new one.

    If fetch has been called recently enough, returns its previous return value. Otherwise, runs callback and returns its new return value.

    Implementation

    Future<T> fetch(Future<T> Function() callback) async {
      if (_cachedStreamSplitter != null) {
        throw StateError('Previously used to cache via `fetchStream`');
      }
      if (_cachedValueFuture == null) {
        _cachedValueFuture = callback();
        await _cachedValueFuture;
        _startStaleTimer();
      }
      return _cachedValueFuture;
    }