diff --git a/spec/Observable-spec.ts b/spec/Observable-spec.ts index 16bdad8f6d..5b8eb18d75 100644 --- a/spec/Observable-spec.ts +++ b/spec/Observable-spec.ts @@ -59,6 +59,20 @@ describe('Observable', () => { }).to.throw(); }); + it('should rethrow if sink has syncErrorThrowable = false', () => { + const observable = new Observable(observer => { + observer.next(1); + }); + + const sink = Subscriber.create(() => { + throw 'error!'; + }); + + expect(() => { + observable.subscribe(sink); + }).to.throw('error!'); + }); + describe('forEach', () => { it('should iterate and return a Promise', (done: MochaDone) => { const expected = [1, 2, 3]; diff --git a/src/Observable.ts b/src/Observable.ts index 74bc9af34f..25ccebbde9 100644 --- a/src/Observable.ts +++ b/src/Observable.ts @@ -199,7 +199,7 @@ export class Observable implements Subscribable { if (operator) { operator.call(sink, this.source); } else { - sink.add(this.source ? this._subscribe(sink) : this._trySubscribe(sink)); + sink.add(this.source || !sink.syncErrorThrowable ? this._subscribe(sink) : this._trySubscribe(sink)); } if (sink.syncErrorThrowable) { diff --git a/src/Subscriber.ts b/src/Subscriber.ts index 36d8459191..daa1536416 100644 --- a/src/Subscriber.ts +++ b/src/Subscriber.ts @@ -68,6 +68,7 @@ export class Subscriber extends Subscription implements Observer { } if (typeof destinationOrNext === 'object') { if (destinationOrNext instanceof Subscriber) { + this.syncErrorThrowable = destinationOrNext.syncErrorThrowable; this.destination = (> destinationOrNext); ( this.destination).add(this); } else {