I have the following code:
import Combine
func login() -> Future<Token, Error> { ... }
func updateImage() -> Future<Status, Never> { ... }
login()
.flatMap { response -> Future<Status, Error> in
// handle response and save token locally
return updateImage()
}
.sink(receiveCompletion: { error in
... //handleError
}, receiveValue: { response in
... // handle response and a different error
})
.store(in: ...)
I want to join login()
and updateImage()
into a sequence. However, I found that zip
is only for parallel requests. I need a way to chain them sequentially, and I am not sure if map
, tryMap
, or mapError
methods can help me achieve that. I need to not only transform but also handle the response data and errors from each function.
How to solve this issue?