Created
July 24, 2017 08:27
-
-
Save LucidityDesign/9e912642c11d832a66a2a9eb284c7255 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Uploader { | |
[...] | |
private func uploadImages() -> Future<Void, UploadError> { | |
let promise = Promise<Void, UploadError>() | |
var imageSequence: [Future<Void, UploadError>]! = [] // 1 | |
let queue = OperationQueue() // 2 | |
queue.maxConcurrentOperationCount = 3 | |
for case let image as Image in self.images { | |
let promise = Promise<Void, UploadError>() // 3 | |
let operation = UploadOperation(image: image, promise: promise) | |
imageSequence.append(promise.future) // 5 | |
queue.addOperation(operation) // 6 | |
} | |
if imageSequence.count == 0 { | |
promise.success() | |
} else { | |
imageSequence.sequence().onComplete(callback: { (_) in | |
promise.success() | |
}).onFailure(callback: { (error) in | |
// throw error | |
}) | |
} | |
return promise.future | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See https://medium.com/@linesapp/use-brightfutures-alamofire-and-operations-to-queue-the-upload-of-multiple-images-23facd3b44f for a description