at_scheduler
v0.2.0
Published
AT event scheduler for your node
Readme
at_scheduler
AT event scheduler for Node.js — run a function at a specific datetime.
Zero dependencies. Recovered and maintained by erubboli.
Usage
const Scheduler = require('at_scheduler');
const scheduler = new Scheduler();
scheduler.addJob(new Date('October 27, 2026 11:13:00'), () => {
console.log('You will see this message at the specified datetime');
});The scheduler loop starts automatically on the first addJob() — calling
init() is optional (and idempotent).
API
new Scheduler(options)
options.interval— polling frequency in ms (default:1000). Jobs fire at most this late relative to their datetime.options.onError— callback receiving exceptions thrown inside job callbacks. Without it, errors are logged to stderr; either way the scheduler keeps running.
scheduler.addJob(datetime, fn)
Schedules fn to run once at datetime (a Date object or ms epoch
timestamp). Each job fires exactly once and is then removed.
scheduler.init()
Starts the event loop manually. Optional and idempotent.
scheduler.clear()
Cancels all pending jobs.
Install
npm install at_schedulerTests
npm testUses Node's built-in test runner (Node >= 18).
History
First published to npm in June 2011 as at_scheduler 0.1.0. The original
GitHub repository (dn2k/node-scheduler) was lost; this tree was recovered
from the npm tarball and fixed in 0.2.0:
- fired jobs are now removed correctly (they used to re-fire every tick, while still-pending jobs could be silently dropped)
- a throwing job callback no longer kills the scheduler
- proper
module.exportsinstead of a leaked global - nodeunit runtime dependency removed; tests use
node:test
License
Dual licensed under MIT and GPLv3.
