deduplicate<T> static method

Future<T> deduplicate<T>(
  1. String key,
  2. Future<T> fn()
)

Implementation

static Future<T> deduplicate<T>(String key, Future<T> Function() fn) {
  if (_inflight.containsKey(key)) {
    AutoPilotLogger.logInfo('Dedup hit: $key');
    return _inflight[key]! as Future<T>;
  }
  final f = fn().whenComplete(() => _inflight.remove(key));
  _inflight[key] = f;
  return f;
}