mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 23:34:24 +01:00
28 lines
534 B
Dart
28 lines
534 B
Dart
import '../../../locator.dart';
|
|
import '../../store/setting.dart';
|
|
|
|
class TryLimiter {
|
|
final Map<String, int> _triedTimes = {};
|
|
|
|
bool shouldTry(String id) {
|
|
final maxCount = locator<SettingStore>().maxRetryCount.fetch()!;
|
|
if (maxCount <= 0) {
|
|
return true;
|
|
}
|
|
final times = _triedTimes[id] ?? 0;
|
|
if (times >= maxCount) {
|
|
return false;
|
|
}
|
|
_triedTimes[id] = times + 1;
|
|
return true;
|
|
}
|
|
|
|
void reset(String id) {
|
|
_triedTimes[id] = 0;
|
|
}
|
|
|
|
void clear() {
|
|
_triedTimes.clear();
|
|
}
|
|
}
|