export class Interval {
    _period;
    _sideEffect;
    _intervalId;
    _tick;
    constructor(period, sideEffect) {
        this._period = period;
        this._sideEffect = sideEffect;
        this._intervalId = null;
        this._tick = 0;
    }
    /**
     * Gets the current tick value.
     *
     * @public
     * @readonly
     */
    get tick() {
        return this._tick;
    }
    /**
     * Starts emitting values at the specified interval.
     * If already running, this is a no-op.
     */
    start() {
        if (this._intervalId !== null) {
            return;
        }
        this._intervalId = setInterval(() => {
            this._tick += this._period;
            this._sideEffect(this._tick);
        }, this._period);
    }
    /**
     * Stops emitting values without resetting the tick.
     */
    stop() {
        if (this._intervalId !== null) {
            clearInterval(this._intervalId);
            this._intervalId = null;
        }
    }
    /**
     * Resets the tick counter to zero.
     */
    reset() {
        this._tick = 0;
    }
    /**
     * Stops and resets the interval.
     */
    destroy() {
        this.stop();
        this.reset();
    }
}
//# sourceMappingURL=Interval.js.map