AnyCancellable: subscription handle. dispose 시 자동 cancel.
💻 코드 패턴
Search debounce (typical)
importCombinefinalclassSearchViewModel:ObservableObject{@Publishedvarquery:String=""@Publishedvarresults:[Item]=[]privatevarbag=Set<AnyCancellable>()init(){$query.debounce(for:.milliseconds(300),scheduler:DispatchQueue.main).removeDuplicates().filter{$0.count>=2}.map{qinURLSession.shared.dataTaskPublisher(for:searchURL(q)).map(\.data).decode(type:[Item].self,decoder:JSONDecoder()).replaceError(with:[])}.switchToLatest()// 이전 검색 cancel.receive(on:DispatchQueue.main).assign(to:&$results)}}