Reputation: 9446
I have a tool on the mac which has data processing interface, web interface and UI. These three interfaces run on three different serial (async) dispatch_queues.(UI runs on main queue)
My data processing interface needs to Stop when the web interface receives the command, Stop. The data processing dispatch_block does not have any dependencies except it needs to listen to Stop command from the web interface.
I am confused about how should I design the data block, so that, I don't have to poll web interface to check if it received the Stop command. The stack for my data block is quite deep(lot of function calls) and I don't want to check in the each function if Stop has been called. The objective is to stop as soon as possible when I receive the Stop command.
I can't rely on the isCancelled
method of NSOperationBlock
as my data block is always running until it receives Stop.
My aim here is not how to design the interfaces in better manner but to quickly exit data block when I receive the Stop command.
I do know this is an age old problem of how to avoid checking a variable all the time. Was just wondering if there is something which could be done.
All suggestions are welcome.
Upvotes: 1
Views: 67
Reputation: 71
You can’t just kill the data processing block. That would lead to memory leaks and unstable state. The isCancelled
approach of NSNSOperation is the best way to go. The Stop command should set a variable that is local to the data processing block and from within the block you check that variable at convenient places and clean up and exit when its set.
Upvotes: 4