1 import { async } from '../scheduler/async';
2 import { isDate } from '../util/isDate';
3 import { Subscriber } from '../Subscriber';
4 import { Notification } from '../Notification';
5 export function delay(delay, scheduler = async) {
6 const absoluteDelay = isDate(delay);
7 const delayFor = absoluteDelay ? (+delay - scheduler.now()) : Math.abs(delay);
8 return (source) => source.lift(new DelayOperator(delayFor, scheduler));
11 constructor(delay, scheduler) {
13 this.scheduler = scheduler;
15 call(subscriber, source) {
16 return source.subscribe(new DelaySubscriber(subscriber, this.delay, this.scheduler));
19 class DelaySubscriber extends Subscriber {
20 constructor(destination, delay, scheduler) {
23 this.scheduler = scheduler;
28 static dispatch(state) {
29 const source = state.source;
30 const queue = source.queue;
31 const scheduler = state.scheduler;
32 const destination = state.destination;
33 while (queue.length > 0 && (queue[0].time - scheduler.now()) <= 0) {
34 queue.shift().notification.observe(destination);
36 if (queue.length > 0) {
37 const delay = Math.max(0, queue[0].time - scheduler.now());
38 this.schedule(state, delay);
42 source.active = false;
45 _schedule(scheduler) {
47 const destination = this.destination;
48 destination.add(scheduler.schedule(DelaySubscriber.dispatch, this.delay, {
49 source: this, destination: this.destination, scheduler: scheduler
52 scheduleNotification(notification) {
53 if (this.errored === true) {
56 const scheduler = this.scheduler;
57 const message = new DelayMessage(scheduler.now() + this.delay, notification);
58 this.queue.push(message);
59 if (this.active === false) {
60 this._schedule(scheduler);
64 this.scheduleNotification(Notification.createNext(value));
69 this.destination.error(err);
73 this.scheduleNotification(Notification.createComplete());
78 constructor(time, notification) {
80 this.notification = notification;
83 //# sourceMappingURL=delay.js.map