ReactivePlusPlus
ReactiveX implementation for C++20
Loading...
Searching...
No Matches
Disposables

Disposable is handle/resource passed from observable to observer via the set_upstream method. Observer disposes this disposable when it wants to unsubscribe from observable. More...

Classes

class  rpp::callback_disposable< Fn >
 Disposable invokes underlying callable on disposing. More...
 
class  rpp::composite_disposable_impl< Container >
 Disposable which can keep some other sub-disposables. When this root disposable is disposed, then all sub-disposables would be disposed too. More...
 
class  rpp::composite_disposable
 Disposable which can keep some other sub-disposables. When this root disposable is disposed, then all sub-disposables would be disposed too. More...
 
class  rpp::disposable_wrapper_impl< TDisposable >
 Main RPP wrapper over disposables. More...
 
struct  rpp::interface_disposable
 Interface of disposable. More...
 

Typedefs

using rpp::disposable_wrapper = disposable_wrapper_impl<interface_disposable>
 Wrapper to keep "simple" disposable. Specialization of rpp::disposable_wrapper_impl.
 
using rpp::composite_disposable_wrapper = disposable_wrapper_impl<interface_composite_disposable>
 Wrapper to keep "composite" disposable. Specialization of rpp::disposable_wrapper_impl.
 

Detailed Description

Disposable is handle/resource passed from observable to observer via the set_upstream method. Observer disposes this disposable when it wants to unsubscribe from observable.

In reactive programming, a disposable is an object that represents a resource that needs to be released or disposed of when it is no longer needed. This can include things like file handles, network connections, or any other resource that needs to be cleaned up after use. The purpose of a disposable is to provide a way to manage resources in a safe and efficient manner. By using disposables, you can ensure that resources are released in a timely manner, preventing memory leaks and other issues that can arise from resource leaks.

There are 2 main purposes of disposables:

  1. Upstream disposable
    This is a disposable that the observable puts into the observer. The upstream disposable keeps some state or callback that should be disposed of when the observer is disposed (== no longer wants to receive emissions, for example, was completed/errored or just unsubscribed) This ensures that any resources used by the observable are properly cleaned up when the observer obtains on_error/on_completed or disposed in any other way.
  2. External disposable
    This is a disposable that allows the observer to be disposed of from outside the observer itself. This can be useful in situations where you need to cancel an ongoing operation or release resources before the observable has completed its work. To achieve this in rpp you can pass disposable to subscribe method or use subscribe_with_disposable overload instead.
Note
In rpp all disposables should be created via rpp::disposable_wrapper_impl instead of manually.
Warning
From user of rpp library it is not really expected to handle disposables manually somehow except of case where user want to control lifetime of observable-observer connection manually.