Skip to content

Commit 88f4872

Browse files
committed
autocomplete: Break search loop when _sortedUsers invalidated
1 parent 46f3723 commit 88f4872

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

lib/model/autocomplete.dart

+8-1
Original file line numberDiff line numberDiff line change
@@ -348,12 +348,19 @@ class MentionAutocompleteView extends ChangeNotifier {
348348
_sortUsers();
349349
}
350350

351-
final iterator = _sortedUsers!.iterator;
351+
final sortedUsers = _sortedUsers!;
352+
final iterator = sortedUsers.iterator;
352353
bool isDone = false;
353354
while (!isDone) {
354355
// CPU perf: End this task; enqueue a new one for resuming this work
355356
await Future(() {});
356357

358+
if (_sortedUsers != sortedUsers) {
359+
// The list of users this loop has been working from has become stale.
360+
// Abort so _startSearch can retry with the new list.
361+
throw ConcurrentModificationError();
362+
}
363+
357364
if (query != _query || !hasListeners) { // false if [dispose] has been called.
358365
return null;
359366
}

0 commit comments

Comments
 (0)