q-manager
v1.0.11
Published
To install dependencies:
Downloads
21
Readme
QueueManager
QueueManager is a TypeScript class that provides a flexible and efficient way to manage asynchronous queues with event-driven control flow.
Features
- Auto-run capability
- Event-driven architecture
- Configurable queue control interval
- Logging option
Installation
npm install queue-manager
Useage
import { QueueManager } from 'q-manager';
// Create a new QueueManager instance
const queueManager = new QueueManager({
autoRun: true,
queueControlInterval: 500,
log: true
});
// Set up a callback for processing queue items
queueManager.setNextCallback((item) => {
console.log(`Processing item: ${item}`);
});
// Add items to the queue
queueManager.push('Item 1').push('Item 2').push('Item 3');
// Listen for events
queueManager.on('next', (item) => {
console.log(`Next item: ${item}`);
});
queueManager.on('end', () => {
console.log('Queue processing completed');
});
Api
Constructor
constructor(options: Partial<QueueOptions> = {})
Creates a new QueueManager instance with the specified options.
Options
- queue: Initial queue items (default: [])
- autoRun: Whether to automatically process queue items (default: false)
- queueControlInterval: Interval for queue control in milliseconds (default: 300)
- log: Whether to log events (default: true)
Methods
push(item: T): this
Adds an item to the queue.
next(): this
Processes the next item in the queue.
reset(): this
Empties the queue.
on(event: string, callback: Function): this
Registers a callback for a specific event.
setNextCallback(callback: (item: T) => void): this
Sets the callback function for processing queue items.
Events
- 'next': Triggered when an item is about to be processed
- 'end': Triggered when queue processing is completed
License
The following npm packages may be included in this product:
These packages each contain the following license and notice below:
MIT License
Copyright (c) Microsoft Corporation.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE