Skip to content

Commit

Permalink
perf(catch): remove tryCatch/errorObject for custom tryCatching, 1.3M…
Browse files Browse the repository at this point in the history
… -> 1.5M ops/sec
  • Loading branch information
benlesh committed Jan 27, 2016
1 parent 3bceb3b commit 35caf74
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/operator/catch.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import {Operator} from '../Operator';
import {Subscriber} from '../Subscriber';
import {Observable} from '../Observable';
import {tryCatch} from '../util/tryCatch';
import {errorObject} from '../util/errorObject';

/**
* Catches errors on the observable to be handled by returning a new observable or throwing an error.
Expand Down Expand Up @@ -39,15 +37,22 @@ class CatchSubscriber<T> extends Subscriber<T> {

error(err: any) {
if (!this.isStopped) {
const result = tryCatch(this.selector)(err, this.caught);
if (result === errorObject) {
super.error(errorObject.e);
} else {
const { destination } = this;
this.unsubscribe();
(<any> destination).remove(this);
result.subscribe(this.destination);
let result: any;

try {
result = this.selector(err, this.caught);
} catch (err) {
this.destination.error(err);
return;
}

this._innerSub(result);
}
}

private _innerSub(result: Observable<any>) {
this.unsubscribe();
(<any>this.destination).remove(this);
result.subscribe(this.destination);
}
}

0 comments on commit 35caf74

Please sign in to comment.