Skip to content

Commit 4e75466

Browse files
committed
perf(Subscriber): double performance adding tryOrUnsub to Subscriber
1 parent dc67d21 commit 4e75466

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed

src/Subscriber.ts

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
import {isFunction} from './util/isFunction';
2-
import {tryCatch} from './util/tryCatch';
3-
import {errorObject} from './util/errorObject';
4-
52
import {Observer} from './Observer';
63
import {Subscription} from './Subscription';
74
import {rxSubscriber} from './symbol/rxSubscriber';
@@ -123,20 +120,23 @@ class SafeSubscriber<T> extends Subscriber<T> {
123120

124121
next(value?: T): void {
125122
if (!this.isStopped && this._next) {
126-
if (tryCatch(this._next).call(this._context, value) === errorObject) {
127-
this.unsubscribe();
128-
throw errorObject.e;
129-
}
123+
this.__tryOrUnsub(this._next, value);
124+
}
125+
}
126+
127+
__tryOrUnsub(fn: Function, value?: any): void {
128+
try {
129+
fn.call(this._context, value);
130+
} catch (err) {
131+
this.unsubscribe();
132+
throw err;
130133
}
131134
}
132135

133136
error(err?: any): void {
134137
if (!this.isStopped) {
135138
if (this._error) {
136-
if (tryCatch(this._error).call(this._context, err) === errorObject) {
137-
this.unsubscribe();
138-
throw errorObject.e;
139-
}
139+
this.__tryOrUnsub(this._error, err);
140140
}
141141
this.unsubscribe();
142142
}
@@ -145,10 +145,7 @@ class SafeSubscriber<T> extends Subscriber<T> {
145145
complete(): void {
146146
if (!this.isStopped) {
147147
if (this._complete) {
148-
if (tryCatch(this._complete).call(this._context) === errorObject) {
149-
this.unsubscribe();
150-
throw errorObject.e;
151-
}
148+
this.__tryOrUnsub(this._complete);
152149
}
153150
this.unsubscribe();
154151
}
@@ -160,4 +157,4 @@ class SafeSubscriber<T> extends Subscriber<T> {
160157
this._parent = null;
161158
_parent.unsubscribe();
162159
}
163-
}
160+
}

0 commit comments

Comments
 (0)