UNPKG

2.71 kBTypeScriptView Raw
1import { SubscriptionLike, TeardownLogic } from './types';
2/**
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.
6 *
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.
11 *
12 * @class Subscription
13 */
14export declare class Subscription implements SubscriptionLike {
15 /** @nocollapse */
16 static EMPTY: Subscription;
17 /**
18 * A flag to indicate whether this Subscription has already been unsubscribed.
19 * @type {boolean}
20 */
21 closed: boolean;
22 /** @internal */
23 protected _parent: Subscription;
24 /** @internal */
25 protected _parents: Subscription[];
26 /** @internal */
27 private _subscriptions;
28 /**
29 * @param {function(): void} [unsubscribe] A function describing how to
30 * perform the disposal of resources when the `unsubscribe` method is called.
31 */
32 constructor(unsubscribe?: () => void);
33 /**
34 * Disposes the resources held by the subscription. May, for instance, cancel
35 * an ongoing Observable execution or cancel any other type of work that
36 * started when the Subscription was created.
37 * @return {void}
38 */
39 unsubscribe(): void;
40 /**
41 * Adds a tear down to be called during the unsubscribe() of this
42 * Subscription.
43 *
44 * If the tear down being added is a subscription that is already
45 * unsubscribed, is the same reference `add` is being called on, or is
46 * `Subscription.EMPTY`, it will not be added.
47 *
48 * If this subscription is already in an `closed` state, the passed
49 * tear down logic will be executed immediately.
50 *
51 * @param {TeardownLogic} teardown The additional logic to execute on
52 * teardown.
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
56 * list.
57 */
58 add(teardown: TeardownLogic): Subscription;
59 /**
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.
63 * @return {void}
64 */
65 remove(subscription: Subscription): void;
66 /** @internal */
67 private _addParent(parent);
68}