-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to run sync operations then concurrent operations in a queue? #14
Comments
You can do it like that: let queue = Queuer(name: "MyCustomQueue")
let concurrentOperationA = ConcurrentOperation { _ in
/// Your task here
}
let concurrentOperationB = ConcurrentOperation { _ in
/// Your task here
}
let concurrentOperationC = ConcurrentOperation { _ in
/// Your task here
}
let concurrentOperationD = ConcurrentOperation { _ in
/// Your task here
}
queue.addChainedOperations([concurrentOperationA, concurrentOperationB]) {
/// Your completion task here
}
queue.addChainedOperations([concurrentOperationB, concurrentOperationC]) {
/// Your completion task here
}
queue.addChainedOperations([concurrentOperationB, concurrentOperationD]) {
/// Your completion task here
}
/// Add this if you want to have a queue completion handler
queue.addCompletionHandler {
/// Your completion task here
} Let me know if this works for you 😄 |
I tried it and it's not exactly what I am looking for because doing so, operation B is triggered 3 times. So I dug a bit and I came up with the perfect solution for my case: class GroupOperation: ConcurrentOperation {
let queue = OperationQueue()
var operations: [ConcurrentOperation] = []
override func execute() {
self.queue.addOperations(self.operations, waitUntilFinished: true)
self.finish(success: success)
}
} Then I call let groupWithCAndD = GroupOperation()
groupWithCAndD.operations([operationC, operationD])
queue.addChainedOperations([
operationA,
operationB,
groupWithCAndD
]) And voilà ! Maybe it can be interesting to add a class GroupOperation in Queuer? And also make the API of
|
Obviously this solution doesn't fit Queuer perfectly as there is no handling of retry etc, but maybe @FabrizioBrancati you can improve the lib with such feature? I would gladly help if I can. |
I would really like to improve the Currently, the B task is executed 3 times, because of this line... Maybe a solution can be to add an I will be very happy to see a PR about that! Please don't hesitate on doing it! |
Have you already started working on that? 😄 |
I will give it a try this week! :) |
I'm closing this issue, because this PR has been merged and is now available on the develop branch 🎉 |
I have to run task A, B, C and D.
Task B needs A.
Tasks C and D need B.
I would like to run a queue in this order
What would be the easiest way to achieve it with Queuer?
The text was updated successfully, but these errors were encountered: