1 import { SubscriptionLike, TeardownLogic } from './types';
3 * Represents a disposable resource, such as the execution of an Observable. A
4 * Subscription has one important method, `unsubscribe`, that takes no argument
5 * and just disposes the resource held by the subscription.
7 * Additionally, subscriptions may be grouped together through the `add()`
8 * method, which will attach a child Subscription to the current Subscription.
9 * When a Subscription is unsubscribed, all its children (and its grandchildren)
10 * will be unsubscribed as well.
14 export declare class Subscription implements SubscriptionLike {
16 static EMPTY: Subscription;
18 * A flag to indicate whether this Subscription has already been unsubscribed.
23 protected _parentOrParents: Subscription | Subscription[];
25 private _subscriptions;
27 * @param {function(): void} [unsubscribe] A function describing how to
28 * perform the disposal of resources when the `unsubscribe` method is called.
30 constructor(unsubscribe?: () => void);
32 * Disposes the resources held by the subscription. May, for instance, cancel
33 * an ongoing Observable execution or cancel any other type of work that
34 * started when the Subscription was created.
39 * Adds a tear down to be called during the unsubscribe() of this
40 * Subscription. Can also be used to add a child subscription.
42 * If the tear down being added is a subscription that is already
43 * unsubscribed, is the same reference `add` is being called on, or is
44 * `Subscription.EMPTY`, it will not be added.
46 * If this subscription is already in an `closed` state, the passed
47 * tear down logic will be executed immediately.
49 * When a parent subscription is unsubscribed, any child subscriptions that were added to it are also unsubscribed.
51 * @param {TeardownLogic} teardown The additional logic to execute on
53 * @return {Subscription} Returns the Subscription used or created to be
54 * added to the inner subscriptions list. This Subscription can be used with
55 * `remove()` to remove the passed teardown logic from the inner subscriptions
58 add(teardown: TeardownLogic): Subscription;
60 * Removes a Subscription from the internal list of subscriptions that will
61 * unsubscribe during the unsubscribe process of this Subscription.
62 * @param {Subscription} subscription The subscription to remove.
65 remove(subscription: Subscription): void;