Skip to content

Commit

Permalink
autocomplete: Break search loop when _sortedUsers invalidated
Browse files Browse the repository at this point in the history
  • Loading branch information
gnprice committed May 14, 2024
1 parent 46f3723 commit 88f4872
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/model/autocomplete.dart
Original file line number Diff line number Diff line change
Expand Up @@ -348,12 +348,19 @@ class MentionAutocompleteView extends ChangeNotifier {
_sortUsers();
}

final iterator = _sortedUsers!.iterator;
final sortedUsers = _sortedUsers!;
final iterator = sortedUsers.iterator;
bool isDone = false;
while (!isDone) {
// CPU perf: End this task; enqueue a new one for resuming this work
await Future(() {});

if (_sortedUsers != sortedUsers) {
// The list of users this loop has been working from has become stale.
// Abort so _startSearch can retry with the new list.
throw ConcurrentModificationError();
}

if (query != _query || !hasListeners) { // false if [dispose] has been called.
return null;
}
Expand Down

0 comments on commit 88f4872

Please sign in to comment.