← All packages

@lacspace/scheduler

v1.0.0Core Runtime Kit0 deps

An in-process job scheduler that actually runs your callbacks — on a recurring interval, a standard 5-field cron schedule, or at a specific time. A self-rescheduling, drift-corrected timer (never setInterval), overlap protection so an async job never runs over itself, jitter, maxRuns and error isolation. Clock and timers are injectable, so it's fully testable without real time. Zero-dependency, isomorphic.

npm i @lacspace/scheduler

Usage

scheduler.ts
import { createScheduler } from "@lacspace/scheduler";

const jobs = createScheduler({
  onError: (err, name) => console.error(`job ${name} failed`, err),
});

// every 30 seconds (duration strings or ms)
jobs.every("30s", () => refreshCache());

// standard 5-field cron — 09:00 on weekdays
jobs.cron("0 9 * * 1-5", () => sendDigest());

// one-shots
jobs.after("5m", () => cleanupTemp());
jobs.at(new Date("2026-12-31T23:59:00"), () => rollOver());

// overlap:false (default) means an async job never runs over itself
jobs.every("1m", syncOrders, { overlap: false });
jobs.stop(); // pause everything

Exports 4

createSchedulerparseDurationnextCronRunmatchesCron

Keywords

schedulerjob-schedulercroncron-jobtask-schedulernode-cron-alternativerecurring-taskssetinterval-alternativein-processzero-dependency

More in Core Runtime Kit

@lacspace/logger

A tiny structured logger for Node and the browser — leveled JSON logging, child loggers, field redaction and pluggable transports (JSON, pretty, in-memory). A log below the active level costs almost nothing: the record is never even built. Errors serialise automatically; secrets get redacted before they leave the logger. Zero-dependency, isomorphic.

@lacspace/result

Typed, functional error handling — Result<T,E> (Ok/Err) and Option<T> (Some/None) so functions return errors as values instead of throwing. Constructors, guards, map/andThen/match, unwrap variants, trySync/tryAsync to wrap throwing code, and an all() combinator that short-circuits on the first error. Tree-shakeable, zero-dependency, isomorphic.

@lacspace/events

A fully type-safe event emitter / tiny pub-sub for Node and the browser. Declare an events map (name → payload type) and get compile-time-checked on/emit. A throwing listener never blocks the others (errors are isolated), adding or removing listeners mid-emit is safe, and once/waitFor/onAny round it out. Comparable to mitt or nanoevents but strongly typed. Zero-dependency, isomorphic.

@lacspace/queue

An in-memory async task queue with a concurrency limit — run up to N async tasks at once and await individual results or the whole drain. Priority ordering, pause/start, clear, onIdle/onEmpty draining, and per-task abort via AbortSignal. A rejected task never stalls the queue. Comparable to p-queue/p-limit but tiny and dependency-free. Isomorphic.

@lacspace/machine

A tiny, fully type-safe finite state machine — declare states, events, guarded transitions, entry/exit/transition actions and a typed context. A pure transition() function plus an interpret() actor with send/subscribe/matches. Context updates are immutable via assign(). A lightweight xstate alternative for the 90% case. Zero-dependency, isomorphic.