ResultDeduplicator<K, V> class

Ensures only one Future<Result<V>> is in flight per key at any time.

When run is called concurrently with the same key, all callers share the same underlying future and receive the same result — no duplicate network calls, no thundering herd:

final dedup = ResultDeduplicator<String, User>();

// All three calls resolve from the single network request.
final results = await Future.wait([
  dedup.run('u1', () => api.fetchUser('u1')),
  dedup.run('u1', () => api.fetchUser('u1')),
  dedup.run('u1', () => api.fetchUser('u1')),
]);

Once the in-flight future completes (success or error), the key is evicted so subsequent calls trigger a fresh fetch.

Constructors

ResultDeduplicator()

Properties

hashCode int
The hash code for this object.
no setterinherited
inFlightCount int
The number of keys with in-flight fetches.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

isInFlight(K key) bool
Whether a fetch for key is currently in progress.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
run(K key, Future<Result<V>> fetch()) Future<Result<V>>
Returns the in-flight future for key if one exists, otherwise calls fetch to start a new one, registers it, and returns it.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited