diff options
author | Yuqian Yang <crupest@crupest.life> | 2025-06-05 22:30:51 +0800 |
---|---|---|
committer | Yuqian Yang <crupest@crupest.life> | 2025-06-09 21:48:00 +0800 |
commit | 3bdca0b90cf8bf5dfd6ff1ab482d857abb4acd2d (patch) | |
tree | 42fd1bf1f0119910c09542fbf475c012404658fd /deno/mail-relay/cron.ts | |
parent | 543fc733da074751e1750603df6931089efab465 (diff) | |
download | crupest-3bdca0b90cf8bf5dfd6ff1ab482d857abb4acd2d.tar.gz crupest-3bdca0b90cf8bf5dfd6ff1ab482d857abb4acd2d.tar.bz2 crupest-3bdca0b90cf8bf5dfd6ff1ab482d857abb4acd2d.zip |
feat(deno): move deno (mail-server) to top level.
Diffstat (limited to 'deno/mail-relay/cron.ts')
-rw-r--r-- | deno/mail-relay/cron.ts | 43 |
1 files changed, 0 insertions, 43 deletions
diff --git a/deno/mail-relay/cron.ts b/deno/mail-relay/cron.ts deleted file mode 100644 index bf0a0be..0000000 --- a/deno/mail-relay/cron.ts +++ /dev/null @@ -1,43 +0,0 @@ -export type CronCallback = (task: CronTask) => Promise<void>; - -export interface CronTaskConfig { - readonly name: string; - readonly interval: number; - readonly callback: CronCallback; - readonly startNow?: boolean; -} - -export class CronTask { - #timerTag: number | null = null; - - constructor(public readonly config: CronTaskConfig) { - if (config.interval <= 0) { - throw new Error("Cron task interval must be positive."); - } - - if (config.startNow === true) { - this.start(); - } - } - - get running(): boolean { - return this.#timerTag != null; - } - - start() { - if (this.#timerTag == null) { - this.#timerTag = setInterval( - this.config.callback, - this.config.interval, - this, - ); - } - } - - stop() { - if (this.#timerTag != null) { - clearInterval(this.#timerTag); - this.#timerTag = null; - } - } -} |