Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inspect enqueued GCD blocks?

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.

like image 742
JPC Avatar asked May 08 '12 17:05

JPC


1 Answers

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.

like image 65
Mike Z Avatar answered Oct 11 '22 05:10

Mike Z