Subscription
Direct Subclass:
Indirect Subclass:
Represents a disposable resource, such as the execution of an Observable. A
Subscription has one important method, unsubscribe
, that takes no argument
and just disposes the resource held by the subscription.
Additionally, subscriptions may be grouped together through the add()
method, which will attach a child Subscription to the current Subscription.
When a Subscription is unsubscribed, all its children (and its grandchildren)
will be unsubscribed as well.
Test:
Constructor Summary
Public Constructor | ||
public |
constructor(unsubscribe: function(): void) |
Member Summary
Public Members | ||
public |
A flag to indicate whether this Subscription has already been unsubscribed. |
Method Summary
Public Methods | ||
public |
add(teardown: TeardownLogic): Subscription Adds a tear down to be called during the unsubscribe() of this Subscription. |
|
public |
remove(subscription: Subscription): void Removes a Subscription from the internal list of subscriptions that will unsubscribe during the unsubscribe process of this Subscription. |
|
public |
unsubscribe(): void Disposes the resources held by the subscription. |
Public Constructors
Public Members
Public Methods
public add(teardown: TeardownLogic): Subscription source
Adds a tear down to be called during the unsubscribe() of this Subscription.
If the tear down being added is a subscription that is already
unsubscribed, is the same reference add
is being called on, or is
Subscription.EMPTY
, it will not be added.
If this subscription is already in an closed
state, the passed
tear down logic will be executed immediately.
Params:
Name | Type | Attribute | Description |
teardown | TeardownLogic | The additional logic to execute on teardown. |
Return:
Subscription | Returns the Subscription used or created to be
added to the inner subscriptions list. This Subscription can be used with
|
public remove(subscription: Subscription): void source
Removes a Subscription from the internal list of subscriptions that will unsubscribe during the unsubscribe process of this Subscription.
Params:
Name | Type | Attribute | Description |
subscription | Subscription | The subscription to remove. |
Return:
void |
public unsubscribe(): void source
Disposes the resources held by the subscription. May, for instance, cancel an ongoing Observable execution or cancel any other type of work that started when the Subscription was created.
Return:
void |