interval-poll-management
v1.0.1
Published
A simple manager for JavaScript intervals with custom IDs
Downloads
2
Maintainers
Readme
interval-manager
A comprehensive manager for JavaScript intervals and polling tasks with custom IDs.
Installation
npm install interval-manager
## Usage
```sh
### Importing the Interval Manager
import intervalManager from 'interval-manager';
### Setting Intervals
// Set an interval with a custom ID
const customId1 = intervalManager.setInterval(() => {
console.log("Custom Interval 1");
}, 1000, 'custom-interval-1');
// Set another interval without a custom ID
const customId2 = intervalManager.setInterval(() => {
console.log("Custom Interval 2");
}, 2000);
### Clearing Intervals
// Clear the interval with the custom ID
intervalManager.clearInterval('custom-interval-1');
// Clear the interval without a custom ID (use the returned ID from setInterval)
intervalManager.clearInterval(customId2);
// Clear all intervals
intervalManager.clearAllIntervals();
### Getting Active Intervals
// Get all active custom IDs
console.log("Active intervals:", intervalManager.getActiveIntervals());
### Polling Tasks
// Start a polling task with a custom name
const pollId = intervalManager.startPolling('poll-task-1', async () => {
console.log("Polling Task 1");
// Perform async operations here
}, 5000);
// Stop a specific polling task
intervalManager.stopPolling('poll-task-1');
// Stop all polling tasks
intervalManager.stopAllPollingTasks();
### License
This project is licensed under the MIT License.