On 26/04/2021 16.53, Simon Marchi wrote: > From: Michael Weghorn > > Previously, the observers attached to an observable were always notified > in the order in which they had been attached. That order is not easily > controlled, because observers are typically attached in _initialize_* > functions, we are called in an undefined order. Just a nit-pick, should that read "functions, WHICH are called in an undefined order."? > > However, an observer may require that another observer attached only > later is called before itself is. > > Therefore, extend the 'observable' class to allow explicitly specifying > dependencies when attaching observers, by adding the possibility to > specify tokens for observers that it depends on. > > To make sure dependencies are notified before observers depending on > them, the vector holding the observers is sorted in a way that > dependencies come before observers depending on them. The current > implementation for sorting uses the depth-first search algorithm for > topological sorting as described at [1]. > > Extend the observable unit tests to cover this case as well. Check that > this works for a few different orders in which the observers are > attached. > > This newly introduced mechanism to explicitly specify dependencies will > be used in a follow-up commit. > > [1] https://en.wikipedia.org/wiki/Topological_sorting#Depth-first_search > > Tested on x86_64-linux (Debian testing). Michael