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