Assume the following simplified code-snippet
import Foundation
import Combine
public class NetworkFetch {
fileprivate var networkPipelines : Set<AnyCancellable> = []
public func loadDataFor(url : URL)
{
URLSession.shared.dataTaskPublisher(for: url)
.map { $0.data }
.decode(type: City.self, decoder: JSONDecoder())
.eraseToAnyPublisher()
.sink(receiveCompletion: {_ in print("Finish")},
receiveValue: { v in
print("\(c)\n")
}
)
.store(in: &networkPipelines)
}
}
For each call of loadDataFor a new combine-pipeline is generated and added to the networkPipelines container. This container grows over time.
What is the correct way to remove such an URLSession-pipeline from this container as soon as all data is fetched by the URLSession-pipeline?