pyapp-kit / psygnal

Python observer pattern (callback/event system). Modeled after Qt Signals & Slots (but independent of Qt)
https://psygnal.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
84 stars 13 forks source link

feat!: Rename `recursion_mode` to `reemission`. Rename `deferred` to `queued`. Add `latest-only` mode. (technically breaking) #296

Closed tlambert03 closed 7 months ago

tlambert03 commented 7 months ago

This PR renames the parameter controlling how callbacks are (re-)invoked when one of the callbacks itself emits the signal currently being emitted. From the new docstrings:

reemission : Literal["immediate", "queued", "latest-only"] | None
    Determines the order and manner in which connected callbacks are invoked when a
    callback re-emits a signal. Default is `"immediate"`.

@Czaki, I was thinking this might actually be the desired behavior for evented models, since it not only makes sure that the current value is always up to date, it also prevents emitting things that are just about to become irrelevant


note: this is technically a breaking change, but we just barely introduced the recursion_mode feature a week or two ago... so there won't be a deprecation

codecov[bot] commented 7 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 100.00%. Comparing base (f6cebcb) to head (277f8c6).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #296 +/- ## ========================================= Coverage 100.00% 100.00% ========================================= Files 22 22 Lines 2009 2033 +24 ========================================= + Hits 2009 2033 +24 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codspeed-hq[bot] commented 7 months ago

CodSpeed Performance Report

Merging #296 will degrade performances by 13.15%

Comparing tlambert03:immediate-drop (277f8c6) with main (f6cebcb)

Summary

❌ 1 (👁 1) regressions ✅ 65 untouched benchmarks

Benchmarks breakdown

Benchmark main tlambert03:immediate-drop Change
👁 test_create_signal_instance 45.4 µs 52.3 µs -13.15%
tlambert03 commented 7 months ago

side question: Do you think you would probably use this mode over 'deferred' for cases like EventedModel when the primary goal of the emitter is to emit the current value?

tlambert03 commented 7 months ago

oh and also: do you like the name immediate-drop? or can you think of a better one?

Czaki commented 7 months ago

side question: Do you think you would probably use this mode over 'deferred' for cases like EventedModel when the primary goal of the emitter is to emit the current value?

Yes. I think it will be better, as in most use cases I need to know only the last value.

oh and also: do you like the name immediate-drop? or can you think of a better one?

I do not have a better name, but I'm bad at naming. Maybe @jni could help.