I want to perform [document doSomething] as soon as [document isBusy] is false. What is the best way to do it? I tried it with a while-loop but that delays the following code, which is not what I want.
I want to perform [document doSomething] as soon as [document isBusy] is false. What
Share
If the action a semantic of your document model
From your question both
isBusyanddoSomethingare features of your document and the action todoSomethingwhenisBusygoes false is appears to be a semantic of your document model and should therefore be implemented by your document model, i.e. something like:Using KVO to implement semantics within a single object is probably unusual, but there are cases where it is useful. In this case it would replace a direct action with an indirect one – KVO would execute
doSomethingat exactly the same point as the above sample code, there would just be a number of intermediate system methods betweensetIsBusyanddoSomethingplus the associated overhead of setting up the KVO.If the action is a semantic of your document’s client
Of course, if the linkage between these two is independent of your document model, i.e. is a semantic of the client of your document, then KVO is appropriate and would be implemented in your client. Your client would register as an observer of your document, i.e. something like:
in a method of the client. Then in your client when a notification of the change is received take the appropriate action: