Skip to content

Commit

Permalink
perf(Subscriber): double performance adding tryOrUnsub to Subscriber
Browse files Browse the repository at this point in the history
  • Loading branch information
benlesh committed Jan 26, 2016
1 parent dc67d21 commit 4e75466
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions src/Subscriber.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import {isFunction} from './util/isFunction';
import {tryCatch} from './util/tryCatch';
import {errorObject} from './util/errorObject';

import {Observer} from './Observer';
import {Subscription} from './Subscription';
import {rxSubscriber} from './symbol/rxSubscriber';
Expand Down Expand Up @@ -123,20 +120,23 @@ class SafeSubscriber<T> extends Subscriber<T> {

next(value?: T): void {
if (!this.isStopped && this._next) {
if (tryCatch(this._next).call(this._context, value) === errorObject) {
this.unsubscribe();
throw errorObject.e;
}
this.__tryOrUnsub(this._next, value);
}
}

__tryOrUnsub(fn: Function, value?: any): void {
try {
fn.call(this._context, value);
} catch (err) {
this.unsubscribe();
throw err;
}
}

error(err?: any): void {
if (!this.isStopped) {
if (this._error) {
if (tryCatch(this._error).call(this._context, err) === errorObject) {
this.unsubscribe();
throw errorObject.e;
}
this.__tryOrUnsub(this._error, err);
}
this.unsubscribe();
}
Expand All @@ -145,10 +145,7 @@ class SafeSubscriber<T> extends Subscriber<T> {
complete(): void {
if (!this.isStopped) {
if (this._complete) {
if (tryCatch(this._complete).call(this._context) === errorObject) {
this.unsubscribe();
throw errorObject.e;
}
this.__tryOrUnsub(this._complete);
}
this.unsubscribe();
}
Expand All @@ -160,4 +157,4 @@ class SafeSubscriber<T> extends Subscriber<T> {
this._parent = null;
_parent.unsubscribe();
}
}
}

0 comments on commit 4e75466

Please sign in to comment.