Skip to content

Commit

Permalink
fix(timeout): throw traceable TimeoutError (#2132)
Browse files Browse the repository at this point in the history
- create TimeoutError contain stacktrace nearby caller instead of scheduler
  • Loading branch information
kwonoj authored and jayphelps committed Nov 17, 2016
1 parent f6fba01 commit 9ebc46b
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/operator/timeout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ import { TimeoutError } from '../util/TimeoutError';
export function timeout<T>(this: Observable<T>, due: number | Date,
errorToSend: any = null,
scheduler: Scheduler = async): Observable<T> {
let absoluteTimeout = isDate(due);
let waitFor = absoluteTimeout ? (+due - scheduler.now()) : Math.abs(<number>due);
return this.lift(new TimeoutOperator(waitFor, absoluteTimeout, errorToSend, scheduler));
const absoluteTimeout = isDate(due);
const waitFor = absoluteTimeout ? (+due - scheduler.now()) : Math.abs(<number>due);
const error = errorToSend || new TimeoutError();
return this.lift(new TimeoutOperator(waitFor, absoluteTimeout, error, scheduler));
}

class TimeoutOperator<T> implements Operator<T, T> {
Expand Down Expand Up @@ -96,6 +97,6 @@ class TimeoutSubscriber<T> extends Subscriber<T> {
}

notifyTimeout(): void {
this.error(this.errorToSend || new TimeoutError());
this.error(this.errorToSend);
}
}

0 comments on commit 9ebc46b

Please sign in to comment.