{"ast":null,"code":"import { async } from '../scheduler/async';\nimport { isDate } from '../util/isDate';\nimport { Subscriber } from '../Subscriber';\nimport { Notification } from '../Notification';\nexport function delay(delay, scheduler = async) {\n  const absoluteDelay = isDate(delay);\n  const delayFor = absoluteDelay ? +delay - scheduler.now() : Math.abs(delay);\n  return source => source.lift(new DelayOperator(delayFor, scheduler));\n}\n\nclass DelayOperator {\n  constructor(delay, scheduler) {\n    this.delay = delay;\n    this.scheduler = scheduler;\n  }\n\n  call(subscriber, source) {\n    return source.subscribe(new DelaySubscriber(subscriber, this.delay, this.scheduler));\n  }\n\n}\n\nclass DelaySubscriber extends Subscriber {\n  constructor(destination, delay, scheduler) {\n    super(destination);\n    this.delay = delay;\n    this.scheduler = scheduler;\n    this.queue = [];\n    this.active = false;\n    this.errored = false;\n  }\n\n  static dispatch(state) {\n    const source = state.source;\n    const queue = source.queue;\n    const scheduler = state.scheduler;\n    const destination = state.destination;\n\n    while (queue.length > 0 && queue[0].time - scheduler.now() <= 0) {\n      queue.shift().notification.observe(destination);\n    }\n\n    if (queue.length > 0) {\n      const delay = Math.max(0, queue[0].time - scheduler.now());\n      this.schedule(state, delay);\n    } else {\n      this.unsubscribe();\n      source.active = false;\n    }\n  }\n\n  _schedule(scheduler) {\n    this.active = true;\n    const destination = this.destination;\n    destination.add(scheduler.schedule(DelaySubscriber.dispatch, this.delay, {\n      source: this,\n      destination: this.destination,\n      scheduler: scheduler\n    }));\n  }\n\n  scheduleNotification(notification) {\n    if (this.errored === true) {\n      return;\n    }\n\n    const scheduler = this.scheduler;\n    const message = new DelayMessage(scheduler.now() + this.delay, notification);\n    this.queue.push(message);\n\n    if (this.active === false) {\n      this._schedule(scheduler);\n    }\n  }\n\n  _next(value) {\n    this.scheduleNotification(Notification.createNext(value));\n  }\n\n  _error(err) {\n    this.errored = true;\n    this.queue = [];\n    this.destination.error(err);\n    this.unsubscribe();\n  }\n\n  _complete() {\n    this.scheduleNotification(Notification.createComplete());\n    this.unsubscribe();\n  }\n\n}\n\nclass DelayMessage {\n  constructor(time, notification) {\n    this.time = time;\n    this.notification = notification;\n  }\n\n} //# sourceMappingURL=delay.js.map","map":null,"metadata":{},"sourceType":"module"}