stabilizeWithThreshold method
Run update until the stabilizer is stable or threshold exceeds.
NOTE: `update is guaranteed to run at least once.
Implementation
@protected
Future<void> stabilizeWithThreshold(int threshold) async {
if (threshold < 1) {
throw ArgumentError.value(threshold, 'threshold', 'Must be >= 1');
}
var count = 0;
bool thresholdExceeded() => count++ > threshold;
// ... and once update says there is no more work to do, we will bail out.
while (!await update()) {
if (thresholdExceeded()) {
throw WillNeverStabilizeError(threshold);
}
}
}