memoizeFuture<T> function

Future<T> Function() memoizeFuture<T>(
  1. AsyncAction<T> fn
)

Cache single async result (memoize Future). Returns a function that runs fn once and reuses the same Future. Roadmap #180.

Implementation

Future<T> Function() memoizeFuture<T>(AsyncAction<T> fn) {
  Future<T>? cached;
  return () async {
    final future = cached ??= fn();
    return await future;
  };
}