krzysiek
krzysiek

Reputation: 187

Is it possible to make dispatch_queue_t empty?

I cannot find any information about it. I have a dispatch_queue_t in my application where I put some tasks to do. But these tasks take some time and it happens that sometimes they shouldn't be called any more so I would like to clean out queue. Is it possible?

Upvotes: 1

Views: 3003

Answers (2)

Catfish_Man
Catfish_Man

Reputation: 41831

No, you can't remove items from a dispatch_queue_t. The two options you have are:

  1. Have you work items check if they've been cancelled before doing their work
  2. Suspend the queue; this won't remove the items, but it will stop them from running

Upvotes: 0

Stavash
Stavash

Reputation: 14314

Use NSOperationQueue for these capabilities - much more convenient. After adding operations to a queue, you can cancel them and even cancel all pending operations if needed.

Here's a good tutorial to get you started: http://www.raywenderlich.com/19788/how-to-use-nsoperations-and-nsoperationqueues

Upvotes: 4

Related Questions