So, I have a group of ASINetworkQueues that currently run together resulting in a race condition when it comes to DB saves. I am trying to create an NSOperationQueue that will will queue each of these "sub queues". I currently have created an NSOperation with a main method that kicks off the "sub queue" to start it's download.
My problem is that each time I add a sub queue to the main queue using "addOperation" it fires that "main" method straight away so my sub queues run concurrently. I was under the impression the main method was fired one at a time. i.e. only for the operation at the top of the queue.
Maybe i'm missing something here but I can't seem to figure out how to stall the other operations until the first one has finished. Also, I can't even seem to get my program into a situation that results in isReady = 0 for the NSOperation.. that always gives back yes.
here's some code:
NOTE: I have set the NSOperation queue maxConcurrentOperations to 1.
NSOperation Main method:
-(void)main {
[subQueue download];
}
Setting up the queue:
ChapterDownloadOperation *cdo = [[ChapterDownloadOperation alloc] init];
cdo.chapter = ch;
[chapterDownloadQueue addOperation:cdo];
[cdo release];
If I add multiple operations the main method fires at the instance it is added to the queue. Is there another function that I should override and use for when that operation is ready to rock. I have a feeling the main method is for setting up the operation.
Any ideas greatly appreciated.
Thanks so much.