get method
TimedComputeOnce<V>
get(
- K key,
- ComputeCall<
V> call, { - PosComputeCall<
V> ? posCompute, - bool resolve = true,
Returns an existing TimedComputeOnce for key or creates a new one.
callis executed at most once per key while retained.posCompute, if provided, is invoked after resolution and before the end of the retention period.- If
resolveis true, the computation may resolve eagerly.
Implementation
TimedComputeOnce<V> get(
K key,
ComputeCall<V> call, {
PosComputeCall<V>? posCompute,
bool resolve = true,
}) {
var computer = _calls[key];
if (computer != null) {
return computer;
}
computer = _calls[key] = TimedComputeOnce(
call,
posCompute: posCompute,
resolve: resolve,
);
computer.whenResolved((v, e, s) {
final prev = _calls[key];
if (!identical(prev, computer)) return;
if (retentionDuration == Duration.zero) {
_removeInternal(key);
} else {
_timers[key]?.cancel();
_timers[key] = Timer(retentionDuration, () {
final prev = _calls[key];
if (identical(prev, computer)) {
_removeInternal(key);
}
});
}
});
return computer;
}