1 | import { 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 | */
|
14 | export declare class Subscription implements SubscriptionLike {
|
15 | private initialTeardown?;
|
16 | /** @nocollapse */
|
17 | static EMPTY: Subscription;
|
18 | /**
|
19 | * A flag to indicate whether this Subscription has already been unsubscribed.
|
20 | */
|
21 | closed: boolean;
|
22 | private _parentage;
|
23 | /**
|
24 | * The list of registered finalizers to execute upon unsubscription. Adding and removing from this
|
25 | * list occurs in the {@link #add} and {@link #remove} methods.
|
26 | */
|
27 | private _finalizers;
|
28 | /**
|
29 | * @param initialTeardown A function executed first as part of the finalization
|
30 | * process that is kicked off when {@link #unsubscribe} is called.
|
31 | */
|
32 | constructor(initialTeardown?: (() => void) | undefined);
|
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 finalizer to this subscription, so that finalization will be unsubscribed/called
|
42 | * when this subscription is unsubscribed. If this subscription is already {@link #closed},
|
43 | * because it has already been unsubscribed, then whatever finalizer is passed to it
|
44 | * will automatically be executed (unless the finalizer itself is also a closed subscription).
|
45 | *
|
46 | * Closed Subscriptions cannot be added as finalizers to any subscription. Adding a closed
|
47 | * subscription to a any subscription will result in no operation. (A noop).
|
48 | *
|
49 | * Adding a subscription to itself, or adding `null` or `undefined` will not perform any
|
50 | * operation at all. (A noop).
|
51 | *
|
52 | * `Subscription` instances that are added to this instance will automatically remove themselves
|
53 | * if they are unsubscribed. Functions and {@link Unsubscribable} objects that you wish to remove
|
54 | * will need to be removed manually with {@link #remove}
|
55 | *
|
56 | * @param teardown The finalization logic to add to this subscription.
|
57 | */
|
58 | add(teardown: TeardownLogic): void;
|
59 | /**
|
60 | * Checks to see if a this subscription already has a particular parent.
|
61 | * This will signal that this subscription has already been added to the parent in question.
|
62 | * @param parent the parent to check for
|
63 | */
|
64 | private _hasParent;
|
65 | /**
|
66 | * Adds a parent to this subscription so it can be removed from the parent if it
|
67 | * unsubscribes on it's own.
|
68 | *
|
69 | * NOTE: THIS ASSUMES THAT {@link _hasParent} HAS ALREADY BEEN CHECKED.
|
70 | * @param parent The parent subscription to add
|
71 | */
|
72 | private _addParent;
|
73 | /**
|
74 | * Called on a child when it is removed via {@link #remove}.
|
75 | * @param parent The parent to remove
|
76 | */
|
77 | private _removeParent;
|
78 | /**
|
79 | * Removes a finalizer from this subscription that was previously added with the {@link #add} method.
|
80 | *
|
81 | * Note that `Subscription` instances, when unsubscribed, will automatically remove themselves
|
82 | * from every other `Subscription` they have been added to. This means that using the `remove` method
|
83 | * is not a common thing and should be used thoughtfully.
|
84 | *
|
85 | * If you add the same finalizer instance of a function or an unsubscribable object to a `Subscription` instance
|
86 | * more than once, you will need to call `remove` the same number of times to remove all instances.
|
87 | *
|
88 | * All finalizer instances are removed to free up memory upon unsubscription.
|
89 | *
|
90 | * @param teardown The finalizer to remove from this subscription
|
91 | */
|
92 | remove(teardown: Exclude<TeardownLogic, void>): void;
|
93 | }
|
94 | export declare const EMPTY_SUBSCRIPTION: Subscription;
|
95 | export declare function isSubscription(value: any): value is Subscription;
|
96 | //# sourceMappingURL=Subscription.d.ts.map |
\ | No newline at end of file |