class
stable
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.
class Subscription implements SubscriptionLike { static EMPTY: Subscription constructor(unsubscribe?: () => void) closed: [object Object] unsubscribe(): void add(teardown: TeardownLogic): Subscription remove(subscription: Subscription): void }
Subscriber
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.
Property | Type | Description |
---|---|---|
EMPTY | Subscription |
constructor(unsubscribe?: () => void)
unsubscribe | Optional. Default is A function describing how to perform the disposal of resources when the |
Property | Type | Description |
---|---|---|
closed | [object Object] | A flag to indicate whether this Subscription has already been unsubscribed. |
unsubscribe(): void
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.
There are no parameters.
void
:
add(teardown: TeardownLogic): Subscription
Adds a tear down to be called during the unsubscribe() of this Subscription. Can also be used to add a child subscription.
teardown | The additional logic to execute on teardown. |
Subscription
: Returns the Subscription used or created to be added to the inner subscriptions list. This Subscription can be used with remove()
to remove the passed teardown logic from the inner subscriptions list.
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.
When a parent subscription is unsubscribed, any child subscriptions that were added to it are also unsubscribed.
remove(subscription: Subscription): void
Removes a Subscription from the internal list of subscriptions that will unsubscribe during the unsubscribe process of this Subscription.
subscription | The subscription to remove. |
void
:
© 2015–2018 Google, Inc., Netflix, Inc., Microsoft Corp. and contributors.
Code licensed under an Apache-2.0 License. Documentation licensed under CC BY 4.0.
https://rxjs.dev/api/index/class/Subscription