Let's say I have a serial dispatch queue and I enqueue several operations on it. I've read that I can't cancel operations once they are dispatched. Is it possible to at the very least view what GCD blocks I've dispatched to maybe make a decision if I want to dispatch another one?
Example, I dispatch Operation A to the queue but soon after my application decides to enqueue another Operation A, so now there are 2 of these operations queued up.
As Kevin Ballard said, you need to elaborate on what exactly you are trying to do. One thing you could do is set a flag, like valid_
and then you can effectively cancel all but the current item in the queue by doing something like this:
dispatch_async(queue, ^{
if (valid_) {
// perform your task here
}
});
Then whenever you want to "cancel" the queue, just set your valid_
flag to NO
.
Again though, give more info on what you are trying to do and I can give you a better answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With