Skip to content

Commit 4564b35

Browse files
wesbillmanBrain
andcommitted
fix(mobile): release completed serial queue tails
Avoid carrying an idle queue across widget scheduler zones. Make existing recovery journeys assert startup instead of waiting indefinitely. Co-authored-by: Brain <1a02c72794dcd0f07058a353bc3a81f4028b8c77c92c87fce6d5c8b85970a20b@buzz.block.builderlab.xyz> Signed-off-by: Wes <[email protected]>
1 parent a55a246 commit 4564b35

2 files changed

Lines changed: 16 additions & 5 deletions

File tree

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
11
/// Serializes operations without letting a failed operation poison later work.
22
class SerialQueue {
3-
Future<void> _tail = Future<void>.value();
3+
Future<void>? _tail;
44

55
Future<T> run<T>(Future<T> Function() operation) {
6-
final result = _tail.then((_) => operation());
7-
_tail = result.then<void>((_) {}, onError: (Object _, StackTrace _) {});
6+
final result = (_tail ?? Future<void>.value()).then((_) => operation());
7+
late final Future<void> tail;
8+
void release() {
9+
// An idle queue must not retain a completed future's scheduler/zone.
10+
// A later operation may already have replaced this tail.
11+
if (identical(_tail, tail)) _tail = null;
12+
}
13+
14+
tail = result.then<void>(
15+
(_) => release(),
16+
onError: (Object _, StackTrace _) => release(),
17+
);
18+
_tail = tail;
819
return result;
920
}
1021
}

‎mobile/test/features/channels/deep_link_dispatcher_test.dart‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,7 @@ void main() {
827827
);
828828
await tester.pump();
829829
await tester.pump();
830-
await recovery.started.future;
830+
expect(recovery.started.isCompleted, isTrue);
831831

832832
expect(find.text('Finish setting up'), findsOneWidget);
833833
expect(find.text('Finishing setup…'), findsOneWidget);
@@ -893,7 +893,7 @@ void main() {
893893
);
894894
await tester.pump();
895895
await tester.pump();
896-
await recovery.started.future;
896+
expect(recovery.started.isCompleted, isTrue);
897897

898898
recovery.completeError(Exception('relay did not respond'));
899899
await tester.pumpAndSettle();

0 commit comments

Comments
 (0)