Skip to content

Instantly share code, notes, and snippets.

@LucidityDesign
Created July 24, 2017 08:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LucidityDesign/9e912642c11d832a66a2a9eb284c7255 to your computer and use it in GitHub Desktop.
Save LucidityDesign/9e912642c11d832a66a2a9eb284c7255 to your computer and use it in GitHub Desktop.
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