timeoutWith.js
2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { async } from '../scheduler/async';
import { isDate } from '../util/isDate';
import { SimpleOuterSubscriber, innerSubscribe, SimpleInnerSubscriber } from '../innerSubscribe';
export function timeoutWith(due, withObservable, scheduler = async) {
return (source) => {
let absoluteTimeout = isDate(due);
let waitFor = absoluteTimeout ? (+due - scheduler.now()) : Math.abs(due);
return source.lift(new TimeoutWithOperator(waitFor, absoluteTimeout, withObservable, scheduler));
};
}
class TimeoutWithOperator {
constructor(waitFor, absoluteTimeout, withObservable, scheduler) {
this.waitFor = waitFor;
this.absoluteTimeout = absoluteTimeout;
this.withObservable = withObservable;
this.scheduler = scheduler;
}
call(subscriber, source) {
return source.subscribe(new TimeoutWithSubscriber(subscriber, this.absoluteTimeout, this.waitFor, this.withObservable, this.scheduler));
}
}
class TimeoutWithSubscriber extends SimpleOuterSubscriber {
constructor(destination, absoluteTimeout, waitFor, withObservable, scheduler) {
super(destination);
this.absoluteTimeout = absoluteTimeout;
this.waitFor = waitFor;
this.withObservable = withObservable;
this.scheduler = scheduler;
this.scheduleTimeout();
}
static dispatchTimeout(subscriber) {
const { withObservable } = subscriber;
subscriber._unsubscribeAndRecycle();
subscriber.add(innerSubscribe(withObservable, new SimpleInnerSubscriber(subscriber)));
}
scheduleTimeout() {
const { action } = this;
if (action) {
this.action = action.schedule(this, this.waitFor);
}
else {
this.add(this.action = this.scheduler.schedule(TimeoutWithSubscriber.dispatchTimeout, this.waitFor, this));
}
}
_next(value) {
if (!this.absoluteTimeout) {
this.scheduleTimeout();
}
super._next(value);
}
_unsubscribe() {
this.action = undefined;
this.scheduler = null;
this.withObservable = null;
}
}
//# sourceMappingURL=timeoutWith.js.map