mininterval-runner
v0.2.1
Published
Repeated execution with minimum interval control.
Downloads
153
Readme
mininterval-runner
Repeated execution with minimum interval control. Useful for running crawlers.
Usage
import { MinIntervalRunner } from 'mininterval-runner';
const task = async (runner) => {
// do something
// Stop executing the task when needed
// runner.stop();
};
// Create a new MinIntervalRunner instance with a minimum interval of 5 minutes and the task function
const runner = new MinIntervalRunner(5 * 60 * 1000, task);
// The following listeners can be set if needed (usually for logging)
// runner.onStart
// runner.onBeforeWaiting
// runner.onAfterWaiting
// runner.onBeforeExecuting
// runner.onAfterExecuting
// runner.onStop
// runner.onTaskError // if this handler returns `true`, the task will restart immediately instead of waiting for the mininterval.
// Start executing the task
await runner.start();