1 import { async } from '../scheduler/async';
2 import { isDate } from '../util/isDate';
3 import { SimpleOuterSubscriber, innerSubscribe, SimpleInnerSubscriber } from '../innerSubscribe';
4 export function timeoutWith(due, withObservable, scheduler = async) {
6 let absoluteTimeout = isDate(due);
7 let waitFor = absoluteTimeout ? (+due - scheduler.now()) : Math.abs(due);
8 return source.lift(new TimeoutWithOperator(waitFor, absoluteTimeout, withObservable, scheduler));
11 class TimeoutWithOperator {
12 constructor(waitFor, absoluteTimeout, withObservable, scheduler) {
13 this.waitFor = waitFor;
14 this.absoluteTimeout = absoluteTimeout;
15 this.withObservable = withObservable;
16 this.scheduler = scheduler;
18 call(subscriber, source) {
19 return source.subscribe(new TimeoutWithSubscriber(subscriber, this.absoluteTimeout, this.waitFor, this.withObservable, this.scheduler));
22 class TimeoutWithSubscriber extends SimpleOuterSubscriber {
23 constructor(destination, absoluteTimeout, waitFor, withObservable, scheduler) {
25 this.absoluteTimeout = absoluteTimeout;
26 this.waitFor = waitFor;
27 this.withObservable = withObservable;
28 this.scheduler = scheduler;
29 this.scheduleTimeout();
31 static dispatchTimeout(subscriber) {
32 const { withObservable } = subscriber;
33 subscriber._unsubscribeAndRecycle();
34 subscriber.add(innerSubscribe(withObservable, new SimpleInnerSubscriber(subscriber)));
37 const { action } = this;
39 this.action = action.schedule(this, this.waitFor);
42 this.add(this.action = this.scheduler.schedule(TimeoutWithSubscriber.dispatchTimeout, this.waitFor, this));
46 if (!this.absoluteTimeout) {
47 this.scheduleTimeout();
52 this.action = undefined;
53 this.scheduler = null;
54 this.withObservable = null;
57 //# sourceMappingURL=timeoutWith.js.map