import { type Overwrite, type PartialWithUndefined } from '@augment-vir/common'; import { type AnyDuration, type FullDate } from 'date-vir'; import { type AsyncObservable } from './async-observable.js'; import { CallbackObservable, type CallbackObservableInit, type UpdateCallback } from './callback-observable.js'; /** * Constructor input for {@link IntervalObservable}. * * @category Internal */ export type IntervalObservableInit = Overwrite, PartialWithUndefined<{ /** The duration between automatic interval updates. Multiple duration units can be set. */ intervalDuration: AnyDuration; /** * When a trigger changes (according to the `equalityCheck`), this `updateCallback` will be * called and the observable's value will be updated again if it generates a new value. * Otherwise, the `updateCallback` callback will only be called the first time (if there is * no `defaultValue` init). */ updateCallback: UpdateCallback; /** * The minimum duration between updates. If multiple automatic or manual triggers occur * within this duration, only the first one will trigger actual updates. */ rateLimit: AnyDuration; /** * If set to true, the interval observable will not automatically start its interval. By * default, the interval observable starts its interval immediately upon construction. * * @default false */ startPaused: boolean; }>>; /** * A variation of {@link CallbackObservable} that automatically calls the callback to update itself * at a regular interval. * * @category Observable */ export declare class IntervalObservable extends CallbackObservable { /** * The duration between update intervals. This can be manually modified at any time to affect * the interval for the next update. */ intervalDuration: AnyDuration | undefined; /** * The minimum duration between updates. Any extra value sets or interval updates within this * duration will be ignored. */ rateLimit: AnyDuration | undefined; /** * The last time a value was set. * * Do not set this externally, it's simply for informational purposes. */ readonly lastSetTime: FullDate | undefined; protected currentTimeoutId: undefined | number | NodeJS.Timeout; constructor(init?: IntervalObservableInit); /** Sets a timeout and runts the update once its finished. */ protected setInterval(): void; /** @returns `true` if the interval triggered an update, `false` otherwise. */ protected runInterval(): boolean; /** * @returns `true` if the operation should _not_ proceed due to rate limiting, otherwise * `false`. */ protected isRateLimited(): boolean; /** * Updates the internal value by calling `updateCallback`. Also ensure that rate limits are * enforced. * * @throws `Error` if `updateCallback` or params have not been set yet. */ protected updateFromCallback(): boolean; /** * Set a new value to the observable. If a promise is used, `value` will be set to the promise * and `value` will be automatically overridden with the resolution or rejection result of the * promise once it's available. * * New resolved values will only be set and listeners will only be fired if it is not equal to * the current value (as determined by `equalityCheck`). * * @returns `true` if the new value was set, `false` otherwise. */ setValue(value: Parameters['setValue']>[0]): boolean; /** * Immediately update the observable and start the interval. * * @returns Whether or not the interval started. This will be `false`, for example, if the * interval is already running. */ resumeInterval(): boolean; /** * Immediately stop the observable's interval. * * @returns Whether or not the interval was stopped. This will be `false`, for example, if the * interval was already stopped. */ pauseInterval(): boolean; /** Clean up all listeners and any other internal state. */ destroy(): void; }