Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Capability to register listeners (observers) on read and write #39

Open
smarie opened this issue Oct 18, 2019 · 2 comments
Open

Capability to register listeners (observers) on read and write #39

smarie opened this issue Oct 18, 2019 · 2 comments
Labels
enhancement New feature or request

Comments

@smarie
Copy link
Owner

smarie commented Oct 18, 2019

We need to clarify

  • the callback signature: probably just (obj, field) for get and (obj, field, value, has_changed) for set.
  • should the observer be called in the same thread ? probably yes for now. Later we could imagine using asyncio.loop.call_soon but that seems overkill for now
  • should the observer be called after setting the value in case of a set observer ? Maybe better to support (A) generators with a single yield and (B) normal methods, in which case they will be called after* the field is set.
  • the name of the option in field() and in the associated decorator (like for validators and converters). Maybe get_observers and set_observers (without the 's' for decorator and corresponding add_xxx method) ?

See https://traitlets.readthedocs.io/en/stable/using_traitlets.html#observe and https://python-3-patterns-idioms-test.readthedocs.io/en/latest/Observer.html

@smarie smarie added the enhancement New feature or request label Oct 18, 2019
@smarie smarie changed the title Capability to register listeners on read and write Capability to register listeners (observers) on read and write Oct 18, 2019
@burnpanck
Copy link

Just a few cents on asnycio.loop.call_soon: There are other event loops out there (I'm a huge fan of trio). It would be great if this feature would play well together with such other loops.

@smarie
Copy link
Owner Author

smarie commented Feb 11, 2022

thanks for the advice ! I did not yet know trio, I'll have a look

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants