Skip to content

Commit 2d97b55

Browse files
gnpricechrisbobbe
authored andcommitted
store: Add debug-only timing control to polling loop
This will be useful for tests.
1 parent fdb9605 commit 2d97b55

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

lib/model/store.dart

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'dart:async';
12
import 'dart:convert';
23
import 'dart:io';
34

@@ -509,8 +510,37 @@ class UpdateMachine {
509510
final String queueId;
510511
int lastEventId;
511512

513+
Completer<void>? _debugLoopSignal;
514+
515+
/// In debug mode, causes the polling loop to pause before the next
516+
/// request and wait for [debugAdvanceLoop] to be called.
517+
void debugPauseLoop() {
518+
assert((){
519+
assert(_debugLoopSignal == null);
520+
_debugLoopSignal = Completer();
521+
return true;
522+
}());
523+
}
524+
525+
/// In debug mode, after a call to [debugPauseLoop], causes the
526+
/// polling loop to make one more request and then pause again.
527+
void debugAdvanceLoop() {
528+
assert((){
529+
_debugLoopSignal!.complete();
530+
return true;
531+
}());
532+
}
533+
512534
void poll() async {
513535
while (true) {
536+
if (_debugLoopSignal != null) {
537+
await _debugLoopSignal!.future;
538+
assert(() {
539+
_debugLoopSignal = Completer();
540+
return true;
541+
}());
542+
}
543+
514544
final result = await getEvents(store.connection,
515545
queueId: queueId, lastEventId: lastEventId);
516546
// TODO handle errors on get-events; retry with backoff

0 commit comments

Comments
 (0)