I'm new to RxSwift and just inherited an old codebase, so please forgive me if this is a silly question.
In the code, data gets updated with the help of Completables and Observables. Below are two methods that loosely illustrate how that's done (obfuscated a bit for privacy purposes):
// note: `getNewData()` returns an Observable
func refreshData() -> Completable {
dataManager.getNewData()
.map { DataRepresentation(fromObject: $0) }
.take(1)
.asSingle()
.flatMapCompletable { data in
self.storageManager.save(data: data)
}
}
// STORAGE MANAGER
func save(data: DataRepresentation) -> Completable {
do {
// PSEUDOCODE: save the data, emit an event about it if necessary.
return Completable.completed()
} catch let error {
return Completable.error(error)
}
}
So, my question is this: let's assume getNewData() allows me to pass in some parameters which will make it so that I don't just get the same data back every time. Moreover, let's say I want to call that method n times, wait for all the calls to come back, then still return a Completable from refreshData() (as to not need to change its signature). Is that sort of thing possible? I was looking into .zip but I'm not sure if it applies here. Thanks.
Here is an updated solution based on all the comments:
Here is a test harness showing that it works (with extensive comments):