I extended NSOperationQueue to add NSBlockOperation with a specific NSString as an identifier.
The identifier value is stored in NSMutableArray , which serves as the registry. This is how I implement the registry.
-(void)addOperation:(NSOperation *)operation withID:(NSString*)operationID { @synchronized(self.queueReference) { [self.queueReference addObject:operationID];
I basically add a termination block that cleans the registry when this particular operation is completed.
However, although this works, I need to add additional detail to the queue.
I use only the queue with the operation of the block, and during the execution of the block I can send a different NSNotification listener depending on how it happened.
What I tried to achieve:
The caller tries to add an NSBlockOperation with identifier to the queue. If there is already such an identifier in the queue, just do not add a block, and the calling class sets itself up as a listener.
What is missing? It is not enough to check the identifier, it may be the case when NSBlockOperation has already sent NSNotification , but the completion block has not yet been called.
Thus, the caller class requests a queue that says that the identifier exists in the registry, and the caller mistakenly set himself to listen to a notification that will never arrive, since it has already been sent.
Instead, there will be a scenario: the caller will request a queue that says that "the identifier is in the registry", but NSNotification sent. And the caller puts the NSBlockOperation in the queue.
Checking the registry using a simple method:
-(BOOL)hasOperationWithID:(NSString*)operationID { @synchronized(self.queueReference) { return [self.queueReference containsObject:operationID]; } }
but at the moment I donโt have a big idea on how to extend such a method. The code I'm working on is kind of "academic", it doesn't serve any specific purpose, I'm just trying to experiment. Therefore, I have great flexibility in the code. But this is a completely new subject for me, so please be as specific as possible, taking into account the shortcomings of the proposed implementation.