1

Although rxcpp::composite_subscription has a method unsubscribe but it doesn't call it on destruction.

Does rxcpp library contains a class that automatically calls unsubscribe when the object goes out of scope?

asmbaty
  • 436
  • 2
  • 11

1 Answers1

1

The reason that the subscription does not call unsubscribe() in its destructor is because it is a cancellation handle, not a RAII object. subscription objects are allowed to be copied and are allowed to be discarded.

If the subscription destructor unsubscribes than discarding the subscription would cancel the work. This is not the contract for a subscription. Keeping the subscription alive does not keep the work alive and discarding the subscription does not stop or destroy the work (this is the weak lifetime that was mentioned correctly in the comments)

The real issue here is that rxcpp modeled lifetime the same way as other rx libraries. Those libraries use GC to manage lifetimes.

A new library is being built that has changes to support structured-concurrency and non-GC lifetime. There are talks and papers by Lewis Baker and Eric Neibler that explain the Single form. The classic rx sequence of values is being prototyped right now.

Kirk Shoop
  • 1,274
  • 9
  • 13