Table of Contents

Class Subscription

Namespace
RxSharp
Assembly
RxSharp.dll

A disposable that composes child teardown logic. Mirrors rxjs's Subscription.

public class Subscription : IDisposable
Inheritance
System.Object
Subscription
Derived

Constructors

Subscription()

Initializes a new instance of the Subscription class with no teardown logic yet.

public Subscription()

Subscription(Action)

Initializes a new instance of the Subscription class that runs finalizer when disposed.

public Subscription(Action finalizer)

Parameters

finalizer Action

The teardown logic to run on Dispose().

Properties

Empty

Gets a shared, already-disposed Subscription instance, useful as a no-op return value.

public static Subscription Empty { get; }

Property Value

Subscription

IsDisposed

Gets a value indicating whether this subscription has been disposed (i.e. unsubscribed).

public bool IsDisposed { get; }

Property Value

bool

Methods

Add(Action)

Registers finalizer to run when this subscription is disposed. Equivalent to Add(IDisposable) with an anonymous disposable wrapping the action.

public void Add(Action finalizer)

Parameters

finalizer Action

The teardown action to add.

Add(IDisposable)

Registers teardown to be disposed when this subscription is disposed. If this subscription is already disposed, teardown is disposed immediately instead. Passing this subscription itself is a no-op (avoids a self-referential dispose loop).

public void Add(IDisposable teardown)

Parameters

teardown IDisposable

The child disposable to add.

Dispose()

Disposes every child teardown added via Add(IDisposable), in the order they were added. Safe to call more than once — subsequent calls are no-ops. If one or more finalizers throw, disposal of the remaining finalizers still proceeds, and any collected exceptions are re-thrown together, wrapped in an UnsubscriptionException.

public void Dispose()

Remove(IDisposable)

Removes a previously added teardown without disposing it, so it will not run when this subscription is later disposed.

public void Remove(IDisposable teardown)

Parameters

teardown IDisposable

The child disposable to remove.

Unsubscribe()

Unsubscribes by disposing this subscription. Equivalent to Dispose(); mirrors rxjs's unsubscribe() naming.

public void Unsubscribe()