share operator - #757
Conversation
Adds `share()` as a shortcut for the `multicast<Subject>() | ref_count()` pipeline. It is templated over the subject with `publish_subject` as the default, mirroring `multicast()`, so `share<some_subject>()` works too. Because it composes the existing `template_multicast_t` and `ref_count()`, the resulting observable type is identical to what `publish() | ref_count()` produces today, making it a drop-in replacement at existing call sites. Covered by a new `share` test case in test_connectable_observable.cpp and a doxygen sample.
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (5)
Included review availability: Your plan includes up to 2 reviews per rolling hour; 1 remains after this review. 📝 WalkthroughWalkthroughThe pull request adds a configurable ChangesShare operator
Estimated code review effort: 3 (Moderate) | ~20 minutes Merge Risk:⚪ Minimal · up to This PR adds a localized share() convenience operator with accompanying tests and documentation; no actionable merge-blocking risk remains beyond normal checks and review. Sequence Diagram(s)sequenceDiagram
participant ObserverA
participant ObserverB
participant ShareOperator
participant Source
ObserverA->>ShareOperator: subscribe
ShareOperator->>Source: subscribe on first observer
ObserverB->>ShareOperator: subscribe
Source-->>ShareOperator: emit value
ShareOperator-->>ObserverA: deliver value
ShareOperator-->>ObserverB: deliver value
ObserverA-->>ShareOperator: unsubscribe
ObserverB-->>ShareOperator: remain subscribed
ObserverB-->>ShareOperator: unsubscribe
ShareOperator->>Source: dispose after last observer
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Adds
share()as a shortcut for themulticast<Subject>() | ref_count()pipeline. It is templated over the subject withpublish_subjectas the default, mirroringmulticast(), soshare<some_subject>()works too.Because it composes the existing
template_multicast_tandref_count(), the resulting observable type is identical to whatpublish() | ref_count()produces today, making it a drop-in replacement at existing call sites.Covered by a new
sharetest case in test_connectable_observable.cpp and a doxygen sample.Summary by CodeRabbit
New Features
shareoperator for multicasting observable values across multiple subscribers.Tests