Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make the NSOperationQueue serial? [closed]

Tags:

I am intending to make the NSOperationQueue serial instead of concurrent.

One way I know is:

NSOperationQueue *globalQueue; globalQueue.maxConcurrentOperationCount =1; 

Is there any other way?

like image 513
lakshmen Avatar asked Feb 21 '13 06:02

lakshmen


People also ask

How do you pause NSOperationQueue?

add a isPaused flag to your NSOperation subclass. implement a copy/move method for the operation's data. if paused, setCancelled: (watch for this change in -main ) create a new operation moving the state from paused operation to new operation.

What is NSOperationQueue in iOS?

Overview. An operation queue invokes its queued NSOperation objects based on their priority and readiness. After you add an operation to a queue, it remains in the queue until the operation finishes its task. You can't directly remove an operation from a queue after you add it. Note.

Which is the best of GCD NSthread or NSOperationQueue?

There is no generic "best" out of the three.

What is the difference between GCD and NSOperationQueue in iOS?

GCD is a low-level C-based API that enables very simple use of a task-based concurrency model. NSOperation and NSOperationQueue are Objective-C classes that do a similar thing. NSOperation was introduced first, but as of 10.5 and iOS 2, NSOperationQueue and friends are internally implemented using GCD .


1 Answers

If you want a serial queue, you are right setting maxConcurrentOperation to one. You can also use [NSOperationQueue mainQueue] instead of creating a new queue, and so queue operations on the main thread. But that is only useful if very short operations are added and so the user interface is not blocked. And on the other hand you have not to worry about threads n synch.

You can add operations to any queue with addOperations:waitUntilFinished:YES or sending the message waitUntilAllOperationsAreFinished every time you add an operation. That way you are serializing operations instead of defining the queue as serial.

like image 199
Gabriel Avatar answered Oct 09 '22 12:10

Gabriel