Skip to content

Commit

Permalink
refactor: use _ctorUnsubscribe flag
Browse files Browse the repository at this point in the history
  • Loading branch information
cartant committed Jul 26, 2020
1 parent 6b61b38 commit 3ef0e1f
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/internal/Subscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export class Subscription implements SubscriptionLike {
*/
constructor(unsubscribe?: () => void) {
if (unsubscribe) {
(this as any)._ctorUnsubscribe = true;
(this as any)._unsubscribe = unsubscribe;
}
}
Expand All @@ -56,7 +57,7 @@ export class Subscription implements SubscriptionLike {
return;
}

let { _parentOrParents, _unsubscribe, _subscriptions } = (this as any);
let { _parentOrParents, _ctorUnsubscribe, _unsubscribe, _subscriptions } = (this as any);

this.closed = true;
this._parentOrParents = null;
Expand All @@ -75,12 +76,15 @@ export class Subscription implements SubscriptionLike {

if (isFunction(_unsubscribe)) {
// It's only possible to null _unsubscribe - to release the reference to
// any teardown function passed in the constructor - if it is actually an
// instance property, as there are some classes that are derived from
// Subscriber (which derives from Subscription) that implement an
// _unsubscribe method as a mechanism for obtaining unsubscription
// notifications and some of those subscribers are recycled.
if (this.hasOwnProperty('_unsubscribe')) {
// any teardown function passed in the constructor - if the property was
// actually assigned in the constructor, as there are some classes that
// are derived from Subscriber (which derives from Subscription) that
// implement an _unsubscribe method as a mechanism for obtaining
// unsubscription notifications and some of those subscribers are
// recycled. Also, in some of those subscribers, _unsubscribe switches
// from a prototype method to an instance property - see notifyNext in
// RetryWhenSubscriber.
if (_ctorUnsubscribe) {
(this as any)._unsubscribe = undefined;
}
try {
Expand Down

0 comments on commit 3ef0e1f

Please sign in to comment.