我有很多(约200)的网址图像,我需要下载的每一项,然后处理(调整),然后更新的高速缓存。 事实是-我只是想有时max3请求在一次,并且由于图像是沉重的,我也不想一个很大的反应"挂"等待处理的(而采取的记忆...).
TLDR我要叫下一次(第4次)网络的的请求后,才 receiveValue
在 sink
被称为上一个第3请求...(即在该网络的响应和处理的都做了...).
将这种流动的工作,并将就举行对等待的网址并没有把它们放在地板上?
还做我需要那个 buffer()
打电话? 我用它看到这个回答: https://stackoverflow.com/a/67011837/2242359
wayTooManyURLsToHandleAtOnce // this is a `[URL]`
.publisher
.buffer(size: .max, prefetch: .byRequest, whenFull: .dropNewest) // NEEDED?
.flatMap(maxPublishers: .max(3)) { url in
URLSession.shared
.dataTaskPublisher(for: url)
.map { (data: Data, _) -> Picture in
Picture(from: data)
}
}
.tryCompactMap {
resizeImage(picture: $0) // takes a while and might fail
}
.receive(on: DispatchQueue.main)
.sink { completion
// handling completion...
} receiveValue: { resizedImage
self.cache.append(resizedImage)
}
.store(...)
self.subject.send(completion: .finished)
在沉结束我的订阅永远吗? (即忽略未来的价值观中发现)