import { isNumeric } from '../util/isNumeric';
import { Observable } from '../Observable';
import { async } from '../scheduler/async';
import { isScheduler } from '../util/isScheduler';
import { isDate } from '../util/isDate';
/**
* We need this JSDoc comment for affecting ESDoc.
* @extends {Ignored}
* @hide true
*/
export class TimerObservable extends Observable {
constructor(dueTime = 0, period, scheduler) {
super();
this.period = -1;
this.dueTime = 0;
if (isNumeric(period)) {
this.period = Number(period) < 1 && 1 || Number(period);
}
else if (isScheduler(period)) {
scheduler = period;
}
if (!isScheduler(scheduler)) {
scheduler = async;
}
this.scheduler = scheduler;
this.dueTime = isDate(dueTime) ?
(+dueTime - this.scheduler.now()) :
dueTime;
}
/**
* Creates an Observable that starts emitting after an `initialDelay` and
* emits ever increasing numbers after each `period` of time thereafter.
*
* Its like {@link interval}, but you can specify when
* should the emissions start.
*
*
*
* `timer` returns an Observable that emits an infinite sequence of ascending
* integers, with a constant interval of time, `period` of your choosing
* between those emissions. The first emission happens after the specified
* `initialDelay`. The initial delay may be a {@link Date}. By default, this
* operator uses the `async` IScheduler to provide a notion of time, but you
* may pass any IScheduler to it. If `period` is not specified, the output
* Observable emits only one value, `0`. Otherwise, it emits an infinite
* sequence.
*
* @example