/******************************************************************** * @author: Kaven * @email: kaven@wuwenkai.com * @website: http://blog.kaven.xyz * @file: [Kaven-Basic] /src/libs/class/Timer.ts * @create: 2023-11-27 11:29:26.635 * @modify: 2025-06-29 08:25:58.353 * @version: 6.0.0 * @times: 13 * @lines: 209 * @copyright: Copyright © 2023-2025 Kaven. All Rights Reserved. * @description: [description] * @license: * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. ********************************************************************/ import { TimeSpan } from "./TimeSpan"; import { KavenLiteEvent } from "./KavenLiteEvent"; import { DateTime } from "./DateTime"; /** * Represents a timer that can be used to schedule recurring tasks * with a specified time interval. */ export declare class Timer { /** * The time interval between each execution of the timer. */ protected interval: TimeSpan; /** * Event that is triggered on each elapsed interval of the timer. */ protected readonly elapsed: KavenLiteEvent; /** * Index representing the number of times the timer has elapsed. */ protected index: number; /** * Identifier of the currently scheduled timeout. */ protected timeoutID?: string | number | NodeJS.Timeout | undefined; protected startDateTime?: DateTime; protected lastInvocationDateTime?: DateTime; /** * Constructs a Timer object with the specified time interval. * @param interval - The time interval for the timer. */ constructor(interval: TimeSpan); /** * Indicates whether the next timer event should be scheduled before triggering the current one. */ ScheduleNextBeforeTrigger: boolean; /** * Gets the time interval of the timer. */ get Interval(): TimeSpan; /** * Sets the time interval of the timer. */ set Interval(value: TimeSpan); /** * Gets a value indicating whether the timer is currently running. */ get IsRunning(): boolean; /** * Gets the date and time when the timer was started. */ get StartDateTime(): DateTime | undefined; /** * Gets the date and time when the timer was last invoked. */ get LastInvocationDateTime(): DateTime | undefined; /** * Gets the date and time when the next timer event is scheduled to occur. */ get NextInvocationDateTime(): DateTime | undefined; /** * Gets the number of times the timer has been invoked. * This property reflects the total count of elapsed intervals, * indicating how many times the timer's 'Elapsed' event has been triggered. */ get Invocations(): number; /** * Gets an event that is triggered on each elapsed interval of the timer. */ get Elapsed(): import("../..").IKavenLiteEvent; /** * Triggers the elapsed event and increments the index. * @returns A promise that resolves with the current index. */ protected trigger(): Promise; /** * Starts the timer. * @throws Error if the timer is already running. */ Start(): void; /** * Stops the timer. */ Stop(): void; /** * Resets the index to zero. */ Reset(): void; /** * Restarts the timer by stopping it, resetting the index, and then starting it again. */ Restart(): void; /** * Schedules the next timer event based on the timer's properties. * @param timer - The timer instance. */ protected static scheduleNext(timer: Timer): void; } //# sourceMappingURL=Timer.d.ts.map