auto reconnect & opt. perf.

This commit is contained in:
lollipopkit
2023-04-23 12:54:54 +08:00
parent 1ccda52f6f
commit fe3055f77c
3 changed files with 133 additions and 131 deletions

View File

@@ -0,0 +1,27 @@
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 resetTryTimes(String id) {
_triedTimes[id] = 0;
}
void clear() {
_triedTimes.clear();
}
}