Reputation: 1702
I have the method below:
private fun bindUploadPhotos(uploadPhotoCommands: List<UploadPhotoCommand>): Disposable {
return Observable.fromIterable(uploadPhotoCommands)
.concatMapSingle { param ->
requestUploadPhoto.getSingle(param)
}
.doFinally {
onAllPhotosUploaded()
}
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe {
onPhotoUploaded()
}
}
I upload photos sequentially. I expect doFinally
to execute after all photos are uploaded successfully. However, it executes immediately.
I am not a RxJava2 master, so I gladly take your different approaches to achieve my purpose.
Upvotes: 0
Views: 403
Reputation: 1069
onComplete
called when all your photos uploaded. so call onAllPhotosUploaded
there
private fun bindUploadPhotos(uploadPhotoCommands: List<UploadPhotoCommand>): Disposable {
return Observable.fromIterable(uploadPhotoCommands)
.flatMapSingle { param ->
requestUploadPhoto.getSingle(param)
}.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe ({onPhotoUploaded},{},{onAllPhotosUploaded()})
}
Upvotes: 3