Skip to content

Commit

Permalink
fix(Promises): escape promise error trap
Browse files Browse the repository at this point in the history
- ensures errors thrown in ,  and  handlers under the  of
  Promise-based observables will throw globally
  • Loading branch information
benlesh committed Sep 23, 2015
1 parent cb393dc commit c69088a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
12 changes: 10 additions & 2 deletions src/observables/PromiseObservable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ export default class PromiseObservable<T> extends Observable<T> {
this.value = value;
subscriber.next(value);
subscriber.complete();
}, err => subscriber.error(err));
}, err => subscriber.error(err))
.then(null, err => {
// escape the promise trap, throw unhandled errors
setTimeout(() => { throw err; })
});
}
} else {
let subscription = new Subscription();
Expand All @@ -43,7 +47,11 @@ export default class PromiseObservable<T> extends Observable<T> {
this._isScalar = true;
this.value = value;
subscription.add(scheduler.schedule(dispatchNext, 0, { value, subscriber }))
}, err => subscription.add(scheduler.schedule(dispatchError, 0, { err, subscriber })));
}, err => subscription.add(scheduler.schedule(dispatchError, 0, { err, subscriber })))
.then(null, err => {
// escape the promise trap, throw unhandled errors
scheduler.schedule(() => { throw err; })
});;
}
return subscription;
}
Expand Down
6 changes: 5 additions & 1 deletion src/util/subscribeToResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ export default function subscribeToResult<T, R>(outerSubscriber: OuterSubscriber
destination.next(x);
destination.complete();
}
}, err => destination.error(err));
}, err => destination.error(err))
.then(null, err => {
// Escaping the Promise trap: globally throw unhandled errors
setTimeout(() => { throw err; });
});
return destination;
} else if (typeof result[$$iterator] === 'function') {
for(let item of result) {
Expand Down

0 comments on commit c69088a

Please sign in to comment.