Closed andreas-0815-qwertz closed 1 year ago
Hi @andreas-0815-qwertz. I am hesitant to make callback order part of the contract with this library. What is your use case?
I'll try to provide a rationale below. For a prominent example, of what I am after, in another language, please look at the Boost Signal2 tutorial.
My use case is a bit entangled: I am building a testbed for an application driven by a cyclic executive. To keep dependencies under control, I have made the 100ms cyclic call observable. One of the observers is a timer provider that can be used by other observers. Obviously, I want to make sure that the timer provider is called before other observers that might use its services.
As long as the execution of my whole application is under my own control, I can ensure such sequencing manually. Managing such dependencies can become complicated to impossible, if:
observed
from a library module that can be used by different usersobserved
in a concurrent environmentI hope this makes sense to you :-) ...
Hey @andreas-0815-qwertz. I am going to leave callback ordering out of observed
for the time being. I am not a good enough programmer to know whether adding that feature would cause more trouble than it's worth. If we do add it, and it turns out to be a maintenance burden, then we can't undo it without breaking backwards compatibility.
As observers are stored in a plain
dict
the order of callbacks is only predictable since Python 3.7, i.e. it will call back in the order of calls toadd_observer
. It would be nice to have an more explicit way to specify the order of callbacks in general, and specifically for older Python versions. The latter case is unimportant for me personally though.