I have a pipeline in ReactiveSwift for uploads. I want to make sure that even if one of the uploads fail, the rest will not be interrupted.
After all of them complete with success or failure, I should either return success from the performUploads
method, or if any have failed, I should return an error, so the next step, the downloads part won't start. Even if there are errors, all uploads should have a chance to upload, they should not be stopped.
Is there a way to figure out if there are any errors after the uploads complete? See the methods here:
let pendingUploadItemsArray: [Items] = ...
func performUploads() -> SignalProducer<(), MyError> {
return upload(pendingUploadItemsArray)
.then(doAnything())
}
private func upload(_ items: [Items]) -> SignalProducer<Signal<(), MyError>.Event, Never> {
let producers = items
.filter { item in
return item.readyForUpload
}
.map { self.upload($0).materialize() }
return SignalProducer.merge(producers)
}
private func upload(_ item: Item) -> SignalProducer<(), MyError> {
return internalUploader.upload(item)
.on(failed: failedToUpload(item),
value: successfullyUploaded(item))
.ignoreValues()
}
where the internalUploader
upload method is:
func upload(_ item: Item) -> SignalProducer<Any, MyError>
And then in another class you would call this uploader:
let sync = self.uploader.performUploads()
.then(startDownloads())
The startDownloads
should only run if all the uploads have completed with success.
Thanks for any insight.
This might be something that should be done in a completely different manner.