Fix crash if autocomplete controller dealloc'd before search task starts

This commit is contained in:
Shadowfacts 2023-09-09 12:28:53 -04:00
parent 4b52cafb9a
commit 519446c5a8
3 changed files with 7 additions and 6 deletions

View File

@ -36,8 +36,8 @@ class AutocompleteEmojisController: ViewController {
.removeDuplicates()
.sink { [unowned self] query in
self.searchTask?.cancel()
self.searchTask = Task {
await self.queryChanged(query)
self.searchTask = Task { [weak self] in
await self?.queryChanged(query)
}
}
}

View File

@ -34,8 +34,8 @@ class AutocompleteHashtagsController: ViewController {
.debounce(for: .milliseconds(250), scheduler: DispatchQueue.main)
.sink { [unowned self] query in
self.searchTask?.cancel()
self.searchTask = Task {
await self.queryChanged(query)
self.searchTask = Task { [weak self] in
await self?.queryChanged(query)
}
}
}

View File

@ -36,8 +36,9 @@ class AutocompleteMentionsController: ViewController {
.debounce(for: .milliseconds(250), scheduler: DispatchQueue.main)
.sink { [unowned self] query in
self.searchTask?.cancel()
self.searchTask = Task {
await self.queryChanged(query)
// weak in case the autocomplete controller is dealloc'd racing with the task starting
self.searchTask = Task { [weak self] in
await self?.queryChanged(query)
}
}
}