vael:cron
UTC five-field cron scheduler and next-occurrence calculator.
Available in the vjs (vaeljs) runtime only; absent in vjs-lite.
Evaluates standard five-field UTC expressions (minute hour dom month dow)
with overlap and missed-tick protection.
import ... from "vael:cron"
vaeljs-core (absent in vaeljs-lite-core)Example
Section titled “Example”import { cron, next } from "vael:cron";
const upcoming = next("0 9 * * 1-5", new Date("2026-01-01T00:00:00Z"));console.log(upcoming?.toISOString());
const job = cron("* * * * *", () => { console.log("tick");});job.dispose();Functions
Section titled “Functions”export function cron(
expression: string,
callback: () => void | PromiseLike<unknown>,
options?: CronOptions,
): CronJob;
Schedule callback on a UTC five-field cron expression
(minute hour day-of-month month day-of-week, max 512 bytes).
At most 1024 active jobs may exist concurrently. One callback executes at a time; returned Promises are awaited before the next tick is eligible.
| Name | Type | Description |
|---|---|---|
expression | string | Five-field UTC cron expression (no extended L/W/#/?). |
callback | () => void | PromiseLike<unknown> | Invoked with no arguments on each eligible tick. |
options optional | CronOptions | Optional { onEvent } observer. |
TypeError— on invalid arguments or unknown options.CronError— withcode"VAEL_CRON_EXPRESSION","VAEL_CRON_LIMIT","VAEL_CRON_NO_OCCURRENCE", or"VAEL_CRON_ARGUMENT".
import { cron } from "vael:cron";
const job = cron("0 * * * *", async () => { console.log("hourly job");}, { onEvent: (ev) => console.warn(ev.type),});job.dispose();export function next(expression: string, after?: Date | number): Date | null;
Compute the first UTC occurrence strictly after after, or null if none
exists within the 100-year (366 * 100 days) search span or Date range.
| Name | Type | Description |
|---|---|---|
expression | string | Five-field UTC cron expression (max 512 bytes). |
after optional | Date | number | Reference Date or epoch milliseconds (defaults to current host UTC time). |
TypeError— whenexpressionorafterhas an invalid type.RangeError— whenafteris an invalidDateor non-finite number.CronError— withcode"VAEL_CRON_EXPRESSION"or"VAEL_CRON_ARGUMENT".
import { next } from "vael:cron";
const after = new Date("2026-01-01T00:00:00Z");console.log(next("30 12 * * *", after)?.toISOString());Classes
Section titled “Classes”CronError
Section titled “CronError”export class CronError extends Error {
override name: "CronError";
code: CronErrorCode;
constructor(code: CronErrorCode, message: string);
}
Error thrown for invalid cron expressions, job limits, missing future occurrences, or invalid cron arguments.
constructor(code: CronErrorCode, message: string);
Construct a CronError.
| Name | Type | Description |
|---|---|---|
code | CronErrorCode | Machine-readable CronErrorCode. |
message | string | Human-readable error message. |
| Property | Type | Description | Since |
|---|---|---|---|
name | "CronError" | Error name ("CronError"). | v0.0.0-alpha.0 |
code | CronErrorCode | Machine-readable cron error code. | v0.0.0-alpha.0 |
Interfaces
Section titled “Interfaces”CronOptions
Section titled “CronOptions”export interface CronOptions {
onEvent?: (event: CronEvent) => void;
}
Options accepted by cron(expression, callback, options).
| Property | Type | Description | Since |
|---|---|---|---|
onEvent optional | (event: CronEvent) => void | Observer invoked with frozen overlap, missed, or error events. Errors thrown by onEvent itself are discarded so the schedule stays alive. | v0.0.0-alpha.0 |
CronJob
Section titled “CronJob”export interface CronJob {
dispose(): void;
}
Frozen handle controlling a scheduled UTC cron job.
Undisposed jobs keep the event loop alive. [Symbol.dispose] is also
installed as an alias for dispose when Symbol.dispose exists in the engine.
CronJob.dispose
Section titled “CronJob.dispose”dispose(): void;
Cancel any pending timer wait and release the host job resource. Idempotent; does not interrupt a callback that is already running.
voidType Aliases
Section titled “Type Aliases”CronErrorCode
Section titled “CronErrorCode”export type CronErrorCode =
| "VAEL_CRON_EXPRESSION"
| "VAEL_CRON_LIMIT"
| "VAEL_CRON_NO_OCCURRENCE"
| "VAEL_CRON_ARGUMENT";
Error codes reported on CronError.code.
CronEvent
Section titled “CronEvent”export type CronEvent =
| {
/** Tick arrived while the previous callback was still running and was skipped. @since 0.0.0-alpha.0 */
readonly type: "overlap";
/** Scheduled UTC occurrence time. @since 0.0.0-alpha.0 */
readonly scheduledTime: Date;
/** Actual UTC wake-up time. @since 0.0.0-alpha.0 */
readonly wokeAt: Date;
}
| {
/** Wake-up was late enough that the following occurrence was already due; stale tick was skipped. @since 0.0.0-alpha.0 */
readonly type: "missed";
/** Scheduled UTC occurrence time that was missed. @since 0.0.0-alpha.0 */
readonly scheduledTime: Date;
/** Actual UTC wake-up time. @since 0.0.0-alpha.0 */
readonly wokeAt: Date;
}
| {
/** Callback threw synchronously, returned a rejected Promise, or the scheduler encountered a wait error. @since 0.0.0-alpha.0 */
readonly type: "error";
/** Thrown or rejected value. @since 0.0.0-alpha.0 */
readonly error: unknown;
/** `true` if a fatal scheduler error terminated the job; `false` for a callback error. @since 0.0.0-alpha.0 */
readonly fatal: boolean;
};
Scheduler lifecycle event passed to options.onEvent.
