Search code examples
iphoneobjective-ciosxcodensoperationqueue

NSOperationQueue with a timer


I would like to use an NSOperationQueue which has got a timer inside it. For example - I download 1 element (complete the 1st NSOperation) then I want to wait for 3 seconds before the compiler goes on to the next operation. After the 2nd NSOperation has been completed I want it to wait for the same 3 seconds and then start the operation number 3.

How can this behaviour be implemented? I have no prior experience of using NSTimer or NSRunLoop and I'm unsure whether I should use them at all.

Thanks in advance.


Solution

  • As long as the operations are executed in background thread;

    You can set the maxConcurrentOperationCount to 1 and use the sleep(3) for 3 seconds in your operation block.