This adds functionality to track the count of ongoing performBlock and save operations. This count allows for the ability to perform clean up when the current operations count reaches zero.
This provides a solution for the scenario in which long-running tasks are executing inside of the block being performed on a MOC and we want MagicalRecord to perform a clean up (For example in an application lockdown). Now a cleanUpWhenFinishedSaving method can be called to only tear down the Core Data stack when any ongoing operations have finished.
It is still the application's responsibility to prevent any future operations from being sent to MagicalRecord. However if cleanUpWhenFinishedSaving has been called, cleanUp will be executed when all performBlock and save operations have finished.
Note Created pull request against develop branch in response to #471
Add save operation count tracking and API to clean up core data stack…
… when all save operations are finished
Implement save operation tracking
Create tests for clean up when finished functionality
Import OSAtomic header
Increment / Decrement operations count for blocks being performed on …
…the context prior to execution of save
Move save decrement to inside completion block
I'm sorry it's taken such a long time to get to this, but are you proposing that we completely shut down the core data stack if the app is in the background? I wouldn't have thought that would be a common thing to do, but I'm keen to hear more — I'll target this for MagicalRecord 3.x.