Skip to content

share operator - #757

Open
btilds wants to merge 1 commit into
AlexInLog:v2from
btilds:share-operator
Open

share operator#757
btilds wants to merge 1 commit into
AlexInLog:v2from
btilds:share-operator

Conversation

@btilds

@btilds btilds commented Aug 16, 2026

Copy link
Copy Markdown

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.

Summary by CodeRabbit

  • New Features

    • Added a share operator for multicasting observable values across multiple subscribers.
    • Automatically connects on the first subscription and disconnects after the last subscriber unsubscribes.
    • Supports configurable subject types, with publish behavior by default.
    • Added usage documentation and examples.
  • Tests

    • Added coverage for shared subscriptions, lazy connections, subscriber lifetimes, and reconnection behavior.

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.
@coderabbitai

coderabbitai Bot commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 9062dfa6-d2cb-46ad-8fc6-d9d24cb8d361

📥 Commits

Reviewing files that changed from the base of the PR and between d54535d and d9eda58.

📒 Files selected for processing (5)
  • src/examples/rpp/doxygen/share.cpp
  • src/rpp/rpp/operators.hpp
  • src/rpp/rpp/operators/fwd.hpp
  • src/rpp/rpp/operators/share.hpp
  • src/tests/rpp/test_connectable_observable.cpp

Included review availability: Your plan includes up to 2 reviews per rolling hour; 1 remains after this review.


📝 Walkthrough

Walkthrough

The pull request adds a configurable share operator. It combines multicast behavior with reference counting, includes tests for subscription lifecycle behavior, and adds a Doxygen example.

Changes

Share operator

Layer / File(s) Summary
Share API and implementation
src/rpp/rpp/operators/fwd.hpp, src/rpp/rpp/operators/share.hpp, src/rpp/rpp/operators.hpp
The public share API uses publish_subject by default and implements sharing through multicast and ref_count.
Share subscription behavior tests
src/tests/rpp/test_connectable_observable.cpp
Tests cover lazy subscription, one shared source subscription, observer-specific unsubscription, completion, and reconnection.
Executable documentation example
src/examples/rpp/doxygen/share.cpp
The example demonstrates two observers receiving values from a shared observable.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to d9eda

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
Loading

Suggested reviewers: alexinlog

Poem

A rabbit shares one stream of cheer,
Two listeners hop and gather near.
One source subscription starts the show,
Each receives the values that flow.
When all hop off, the stream lets go.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely identifies the main change: adding the share operator.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@AlexInLog AlexInLog left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! thanks

@btilds

btilds commented Aug 19, 2026

Copy link
Copy Markdown
Author

LGTM! thanks

Seems like some ci tests failed; mind looking into it?

@AlexInLog

Copy link
Copy Markdown
Owner

LGTM! thanks

Seems like some ci tests failed; mind looking into it?

Yeah, I'm trying. Looks like qt is outdated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants