task-scheduler-package
v1.0.1
Published
This module is mainly used to demonstrate task scheduling with an example
Readme
TaskScheduler Class
The TaskScheduler class is designed to handle scheduling of tasks with various options such as delays, intervals, repetitions, and priorities. It provides a robust system for managing and executing scheduled tasks efficiently.
Features:
Task Scheduling: Supports delay, interval, and repetition for tasks. Priority Management: Allows tasks to be sorted and executed based on priority levels. Pause and Resume: Tasks can be paused and resumed as needed. Dynamic Modifications: Provides methods to modify task timings and intervals even after scheduling.
Key Concepts
- Task Properties:
name: The name of the task. callback: The function that executes when the task is run. interval: The interval (in milliseconds) at which the task repeats. delay: The initial delay (in milliseconds) before the task starts. repeat: Boolean flag to determine if the task repeats after each interval. priority: The priority level of the task, with higher numbers indicating higher priority.
- Task Lifecycle:
Scheduling: Tasks can be scheduled with specific properties. Execution: Tasks are run based on their schedule and priority. Modification: Tasks can be adjusted for intervals, delays, or paused/resumed. Removal: Tasks can be removed either manually or when there are no more pending tasks.
3.Methods:
addTask(taskDetails): Adds a new task with the provided configuration. removeTask(taskId): Removes a task by its unique ID. pauseTask(taskId): Pauses a task, preventing it from running. resumeTask(taskId): Resumes a paused task. adjustTaskInterval(taskId, newInterval): Adjusts the interval of a repeatable task. modifyTaskTime(taskId, { newDelay, newInterval }): Modifies both delay and interval of a task. cancelAllTasks(): Cancels all scheduled tasks.
- Internal Handling:
Tasks are sorted based on priority and executed in order.If no tasks are left, the scheduler is stopped.
