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`');
      }
      return _cachedValueFuture ??= callback()
        ..whenComplete(_startStaleTimer).ignore();
    }