asad-task-scheduler
v1.0.0
Published
Task Scheduler is a simple JavaScript package that allows you to schedule and manage tasks within your Node.js applications.
Downloads
1
Readme
Task Scheduler
Task Scheduler is a simple JavaScript package that allows you to schedule and manage tasks within your Node.js applications.
Installation
Install the package via npm:
npm install asad-task-scheduler
Usage
Require the
TaskScheduler
class in your Node.js application:const TaskScheduler = require('your-task-scheduler-package-name');
Create a new instance of
TaskScheduler
:const scheduler = new TaskScheduler();
Define your task function:
function myTask() { console.log('Executing my task...'); }
Schedule your task to run at a specified interval:
scheduler.scheduleTask(myTask, intervalInMilliseconds);
Cancel all tasks when they are no longer needed:
scheduler.cancelAllTasks();
Example
const TaskScheduler = require('your-task-scheduler-package-name');
// Create a new instance of TaskScheduler
const scheduler = new TaskScheduler();
// Define a task function
function myTask() {
console.log('Executing my task...');
}
// Schedule the task to run every 2 seconds
scheduler.scheduleTask(myTask, 2000);
// After some time, cancel all tasks
setTimeout(() => {
scheduler.cancelAllTasks();
console.log('All tasks cancelled.');
}, 10000); // Cancel after 10 seconds
License
This package is licensed under the MIT License. See the LICENSE file for details.