I have a timer that performs an operation on a property if it is not nil, but between checking for nil and performing the operation, an event sets the property to nil. There are in fact several events all of which could set the property to nil. There are also other properties that the timer is checking that are in the same boat.
What’s the most elegant and scalable way to resolve this?
- Wrap every use of the property in a synchronized block?
- Set/release a lock at the beginning of the timer and check wait for the lock in each event?
- Something else?
I’m not too sure on your exact situation but you might want to consider writing a custom setter to the property that will cancel the timer when it is set to nil?