registerPrecondition method
Precondition
registerPrecondition(
- PreconditionId id,
- PreconditionFunction preconditionFunction, {
- String? description,
- Iterable<
_Dependency> dependsOn = const [], - dynamic resolveTimeout = const Duration(seconds: 10),
- dynamic staySatisfiedCacheDuration = Duration.zero,
- dynamic stayFailedCacheDuration = Duration.zero,
- InitPreconditionFunction? initFunction,
Use this method to register your PreconditionFunction with given unique id.
Optionally:
- provide
statusBuilder
which will be later used to render feedback to the user (seePrecondition.build
) - limit evaluation duration with
resolveTimeout
, after which the precondition is evaluated as PreconditionStatus.isFailed (default is 10s) - allow precondition to cache its positive and/or negative result with
satisfiedCache
andnotSatisfiedCache
. - specify
dependsOn
- set of preconditions which must be satisfied before the repository attempts to evaluate this one
Implementation
Precondition registerPrecondition(
PreconditionId id,
PreconditionFunction preconditionFunction, {
String? description,
Iterable<_Dependency> dependsOn = const [],
resolveTimeout = const Duration(seconds: 10),
staySatisfiedCacheDuration = Duration.zero,
stayFailedCacheDuration = Duration.zero,
InitPreconditionFunction? initFunction,
}) {
for (var dId in dependsOn) {
var dp = _known[dId._targetId];
if (dp == null) throw Exception("Precondition '$id' depends on '$dId', which is not (yet?) registered");
dId._target = dp;
}
if (_known.containsKey(id)) {
throw Exception("Precondition '$id' is already registered");
}
var _p = Precondition._(
id,
preconditionFunction,
Set.unmodifiable(dependsOn),
this,
description: description,
staySatisfiedCacheDuration: staySatisfiedCacheDuration,
stayFailedCacheDuration: stayFailedCacheDuration,
initFunction: initFunction,
resolveTimeout: resolveTimeout,
);
_known[id] = _p;
_log.info("Registering $_p");
notifyListeners();
return _p;
}