mirror of
https://github.com/mas-cli/mas
synced 2025-02-16 12:38:30 +00:00
🔥 Attempt all downloads, reject with first error
This commit is contained in:
parent
9f340bdce9
commit
25045fa0dd
1 changed files with 13 additions and 3 deletions
|
@ -15,10 +15,20 @@ import StoreFoundation
|
|||
/// - Parameter appIDs: The IDs of the apps to be downloaded
|
||||
/// - Parameter purchase: Flag indicating whether the apps needs to be purchased.
|
||||
/// Only works for free apps. Defaults to false.
|
||||
/// - Returns: A promise that completes when the downloads are complete.
|
||||
/// - Returns: A promise that completes when the downloads are complete. If any fail,
|
||||
/// the promise is rejected with the first error, after all remaining downloads are attempted.
|
||||
func downloadAll(_ appIDs: [UInt64], purchase: Bool = false) -> Promise<Void> {
|
||||
appIDs.reduce(Promise<Void>.value) { promise, appID in
|
||||
promise.then { download(appID, purchase: purchase) }
|
||||
var firstError: Error?
|
||||
return appIDs.reduce(Guarantee<Void>.value(())) { previous, appID in
|
||||
previous.then { download(appID, purchase: purchase).recover { error in
|
||||
if firstError == nil {
|
||||
firstError = error
|
||||
}
|
||||
} }
|
||||
}.done {
|
||||
if let error = firstError {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue