Re: Changing head item on a (GCD) Queue


Dave
 

Hi Quincey,

I thought about using an NSOperationQueue but from what I can tell, when an operation is cancelled it stays on the queue until the NSOperation method gets called which check the “Cancel” property, this means that there will still be a lot of useless Operations in the queue, unless I misunderstand the documentation?

As an example:

Head: Data 122 (Executing)
Data 123 (Cancelled)
Data 124 (Cancelled)
Data 130 (Cancelled)
Data 136

New Data received: Data 137

This will cause Data 136 to be Cancelled and Data 137 to be added to the end of the queue.

Is this how it would have to work?

All the Best
Dave

On 6 Mar 2018, at 00:14, Quincey Morris <quinceymorris@...> wrote:

On Mar 5, 2018, at 05:04 , Dave <dave@...> wrote:

I’m trying to figure out the best (modern) way to this which I assume is to use GCD?

Not necessarily. Both NSOperationQueue and GCD can cancel un-started operations, but NSOperationQueue has a mechanism for cancelling running operations too. Overall, you probably get more control over the queue with NSOperationQueue.


Join cocoa@apple-dev.groups.io to automatically receive all group messages.