thideyetask
v1.0.1
Published
Task Scheduler is a simple JavaScript package that allows you to schedule and manage recurring tasks within your Node.js applications. It provides an easy-to-use interface for scheduling tasks to run at specified intervals.
Downloads
1
Readme
Task Scheduler
Description
Task Scheduler is a simple JavaScript package that allows you to schedule and manage recurring tasks within your Node.js applications. It provides an easy-to-use interface for scheduling tasks to run at specified intervals.
Installation
To install the Task Scheduler package, you can use npm:
npm install thideyetask
Usage
- Import the
thideyetask
class into your Node.js application:
const TaskScheduler = require('task-scheduler');
- Create a new instance of
TaskScheduler
:
const scheduler = new TaskScheduler();
- Define your tasks as functions:
const task1 = () => {
console.log('Task 1 executed at', new Date());
};
const task2 = () => {
console.log('Task 2 executed at', new Date());
};
- Schedule tasks to run at specified intervals using the
scheduleTask
method:
scheduler.scheduleTask(task1, 2000); // Task 1 every 2 seconds
scheduler.scheduleTask(task2, 5000); // Task 2 every 5 seconds
- Tasks will run indefinitely until explicitly cancelled. To cancel all tasks, use the
cancelAllTasks
method:
scheduler.cancelAllTasks();
Example
const TaskScheduler = require('task-scheduler');
const scheduler = new TaskScheduler();
const task1 = () => {
console.log('Task 1 executed at', new Date());
};
const task2 = () => {
console.log('Task 2 executed at', new Date());
};
scheduler.scheduleTask(task1, 2000);
scheduler.scheduleTask(task2, 5000);
// Tasks will run indefinitely until explicitly cancelled
// To cancel all tasks
// scheduler.cancelAllTasks();
License
This project is licensed under the MIT License - see the LICENSE file for details.