Skip to content

Commit dfefa8a

Browse files
committed
store [nfc]: Add UpdateMachine.debugPrepareLoopError
We'll use this for testing further error-handling logic.
1 parent 61406ba commit dfefa8a

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

lib/model/store.dart

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -954,6 +954,7 @@ class UpdateMachine {
954954
}
955955

956956
Completer<void>? _debugLoopSignal;
957+
Object? _debugLoopError;
957958

958959
/// In debug mode, causes the polling loop to pause before the next
959960
/// request and wait for [debugAdvanceLoop] to be called.
@@ -965,11 +966,29 @@ class UpdateMachine {
965966
}());
966967
}
967968

969+
/// In debug mode, causes the next [debugAdvanceLoop] call to induce
970+
/// the given error to be thrown from the polling loop.
971+
void debugPrepareLoopError(Object error) {
972+
assert(() {
973+
assert(_debugLoopError == null);
974+
_debugLoopError = error;
975+
return true;
976+
}());
977+
}
978+
968979
/// In debug mode, after a call to [debugPauseLoop], causes the
969980
/// polling loop to make one more request and then pause again.
981+
///
982+
/// If [debugPrepareLoopError] was called since the last [debugAdvanceLoop]
983+
/// or [debugPauseLoop], the polling loop will throw the prepared error
984+
/// instead of making a request.
970985
void debugAdvanceLoop() {
971986
assert((){
972-
_debugLoopSignal!.complete();
987+
if (_debugLoopError != null) {
988+
_debugLoopSignal!.completeError(_debugLoopError!);
989+
} else {
990+
_debugLoopSignal!.complete();
991+
}
973992
return true;
974993
}());
975994
}

0 commit comments

Comments
 (0)