I'm using RxJava to iterate over a list of files, making a network call to upload each file, then collect the files that were successfully uploaded in a list and persist those files in the subscriber on success.
This code works, except for when an error occurs. The behavior should be that it logs the error and continues, which it does, except when an error occurs the subscriber's onSuccess lambda never gets called.
Is the observer expecting the same number of elements to be emitted as are in the original iterable? How can I skip the errors and have it complete once all items have been iterated over? Is there something other than Single.never()
that will accomplish not forwarding the error to the downstream?
queryFiles()?.let { files ->
Observable.fromIterable(files)
.flatMapSingle { file ->
uploadFile(file)
.onErrorResumeNext { error ->
log(error)
Single.never() // if this is returned onSuccess is never called
}
.map { response ->
file.id = response.id
file
}
}
.toList()
.subscribe( { uploadedFiles ->
persist(uploadedFiles) // if error occurs above, this is never called
}, { error ->
log(error)
})
}