Skip to content

Instantly share code, notes, and snippets.

@jacobsapps
Created January 15, 2026 10:39
Show Gist options
  • Select an option

  • Save jacobsapps/c61528b13ea92f2b4b947ea8ce911e0f to your computer and use it in GitHub Desktop.

Select an option

Save jacobsapps/c61528b13ea92f2b4b947ea8ce911e0f to your computer and use it in GitHub Desktop.
protocol SearchService {
// stream results directly to view model
var searchResults: AsyncStream<[User]>
func search(query: String) async throws
// cursor-based pagination
func nextPage(query: String, after user: User) -> async throws
}
final class SearchServiceImpl: SearchService {
private var searchTask: Task<Void, Error>?
func search(query: String) async throws {
searchTask?.cancel()
searchTask = {
try Task.checkCancellation()
// perform search network request
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment