ReactiveX / RxCpp

Reactive Extensions for C++
Apache License 2.0
3.05k stars 395 forks source link

operators: Add ref_count(other) operator overload. #485

Closed iam closed 5 years ago

iam commented 5 years ago

The existing connectable_observable.ref_count() operator calls connect on the source when it's subscribed to.

Generalize this by allowing an optional parameter other, i.e. observable.ref_count(connectable_observable other) to be used as the connect target.

Useful for implementing diamond graphs while retaining composability:

     A
   /   \
  B     C
   \   /
     D
     |
     E

auto A = ... | publish();
auto B = A | ...;
auto C = A | ...;
auto D = B | merge(C) | ref_count(A);
auto E = D | ...;

E | subscribe(...);

Resolves: https://github.com/ReactiveX/RxCpp/issues/484