Skip to content

Commit d52dedd

Browse files
committed
store [nfc]: Pull _maybeReportToUserTransientError out of poll method
This method has gotten awfully long and tangly. Here's a first step on giving it some more organized structure.
1 parent afbd44b commit d52dedd

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

lib/model/store.dart

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,28 +1008,10 @@ class UpdateMachine {
10081008
}
10091009
static BackoffMachine? __unexpectedErrorBackoffMachine;
10101010

1011-
/// This controls when we start to report transient errors to the user when
1012-
/// polling.
1013-
///
1014-
/// At the 6th failure, the expected time elapsed since the first failure
1015-
/// will be 1.55 seocnds.
1016-
static const transientFailureCountNotifyThreshold = 5;
1017-
10181011
void poll() async {
10191012
assert(!_disposed);
10201013
try {
10211014
BackoffMachine? backoffMachine;
1022-
int accumulatedTransientFailureCount = 0;
1023-
1024-
/// This only reports transient errors after reaching
1025-
/// a pre-defined threshold of retries.
1026-
void maybeReportToUserTransientError(Object error) {
1027-
accumulatedTransientFailureCount++;
1028-
if (accumulatedTransientFailureCount > transientFailureCountNotifyThreshold) {
1029-
_reportToUserErrorConnectingToServer(error);
1030-
}
1031-
}
1032-
10331015
while (true) {
10341016
if (_debugLoopSignal != null) {
10351017
await _debugLoopSignal!.future;
@@ -1086,7 +1068,7 @@ class UpdateMachine {
10861068
assert(debugLog('Transient error polling event queue for $store: $e\n'
10871069
'Backing off, then will retry…'));
10881070
if (shouldReportToUser) {
1089-
maybeReportToUserTransientError(e);
1071+
_maybeReportToUserTransientError(e);
10901072
}
10911073
await (backoffMachine ??= BackoffMachine()).wait();
10921074
if (_disposed) return;
@@ -1114,7 +1096,7 @@ class UpdateMachine {
11141096
store.isLoading = false;
11151097
// Dismiss existing errors, if any.
11161098
reportErrorToUserBriefly(null);
1117-
accumulatedTransientFailureCount = 0;
1099+
_accumulatedTransientFailureCount = 0;
11181100

11191101
final events = result.events;
11201102
for (final event in events) {
@@ -1191,6 +1173,24 @@ class UpdateMachine {
11911173
}
11921174
}
11931175

1176+
/// This controls when we start to report transient errors to the user when
1177+
/// polling.
1178+
///
1179+
/// At the 6th failure, the expected time elapsed since the first failure
1180+
/// will be 1.55 seocnds.
1181+
static const transientFailureCountNotifyThreshold = 5;
1182+
1183+
int _accumulatedTransientFailureCount = 0;
1184+
1185+
/// This only reports transient errors after reaching
1186+
/// a pre-defined threshold of retries.
1187+
void _maybeReportToUserTransientError(Object error) {
1188+
_accumulatedTransientFailureCount++;
1189+
if (_accumulatedTransientFailureCount > transientFailureCountNotifyThreshold) {
1190+
_reportToUserErrorConnectingToServer(error);
1191+
}
1192+
}
1193+
11941194
void _reportToUserErrorConnectingToServer(Object error) {
11951195
final localizations = GlobalLocalizations.zulipLocalizations;
11961196
reportErrorToUserBriefly(

0 commit comments

Comments
 (0)