Suppose I have an application that downloads files from a server and uploads them to another server.
The downloading files do not necessarily exist on the server.
So, when the file does not exist, I want to skip it, not to proceed to upload it and make sure that only existing files are downloaded/uploaded. (i.e. no single downloading exception should stop all other downloading and uploading processes)
The Future should be either successful with no results(Unit) or failure with exception along with the failed path.
What is the standard way to handle this situation?
def downloadFile(path: String): Future[DownloadFile]
def uploadFile(file: DownloadFile): Future[Unit]
Future.sequence(
paths.map { path =>
for {
downloadedFile <- downloadFile(path)
_ <- uploadFile(downloadedFile)
} yield Unit
}
)