fetch method

Future<T> fetch (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.


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