Gathering detailed insights and metrics for @randajan/queue
Gathering detailed insights and metrics for @randajan/queue
Tiny javascript library to pack many calling of the same function to one execution
npm install @randajan/queue
Typescript
Module System
Node Version
NPM Version
JavaScript (100%)
Love this project? Help keep it running — sponsor us today! 🚀
Total Downloads
702
Last Day
1
Last Week
5
Last Month
24
Last Year
702
20 Commits
1 Watching
1 Branches
1 Contributors
Minified
Minified + Gzipped
Latest Version
0.1.6
Package Id
@randajan/queue@0.1.6
Unpacked Size
14.33 kB
Size
4.61 kB
File Count
4
NPM Version
10.1.0
Node Version
20.5.1
Publised On
02 Nov 2024
Cumulative downloads
Total Downloads
Last day
0%
1
Compared to previous day
Last week
25%
5
Compared to previous week
Last month
300%
24
Compared to previous month
Last year
0%
702
Compared to previous year
1
Tiny javascript library to pack many calling of the same function to one execution
This project implements a task queue for delayed processing in JavaScript. The task queue is designed to be flexible and robust, allowing you to capture and process small tasks and execute them all at once. This task queue is a useful tool for managing asynchronous operations in JavaScript and can be used in your application to efficiently handle task processing.
To install the package, use npm: npm install @your-package-name
1 2// Import the module 3import { createQueue } from '@randajan/queue'; 4 5// Define the tasks processing function 6const processTasks = (tasks) => { console.log(tasks); } 7 8// Create a queue 9const queue = createQueue(processTasks, { softMs: 100 }); 10 11// Add tasks to the queue 12queue('task1'); 13queue('task2');
createQueue(processQueue, options)
Creates a new task queue.
Return of this call will be a function that will push any arguments to the queue for later procesing via processQueue. Pushing arguments into queue return a Promise that will eventually resolve with the result of calling processQueue function.
processQueue
(required)A function that processes tasks in the queue. It must be passed as the first parameter when creating the queue. Without this function, the queue has no purpose and will result in an error.
options
(optional)An object containing configuration options for the queue:
Parameter | Default | Description |
---|---|---|
softMs | 0 | The soft time limit (in milliseconds) before executing the task processing function after the last task is added to the queue. If tasks keep coming in before this time limit is reached, the execution of the tasks will be delayed. |
hardMs | 0 | The hard time limit (in milliseconds) before forcefully executing the task processing function, regardless of whether new tasks are added or not. |
maxSize | 0 | The maximum size of the queue. Once the queue reaches this size, the task processing function will be executed immediately. Value 0 means no maximum size limit. |
returnResult | false | When true the queue Promise will wait and return the result of the processQueue call otherwise it return imediately nothing |
args | [] | Arguments that will be passed to the processQueue function |
pass | "all" | Specifies how tasks are passed to the processQueue function. Possible values are:- "all" : All tasks in the queue are passed as an array at the beginning of the arguments to the processQueue function.- "first" : Only the first task in the queue is passed as individual arguments to the processQueue function.- "last" : Only the last task in the queue is passed as individual arguments to the processQueue function. |
onInit | undefined | When function is provided it will be called right after initialization of new queue |
There is extra properties that is append to the function retrieved from calling createQueue(...)
Parameter | Description |
---|---|
isPending | Indicates whether there are tasks pending in the queue. Returns true if there are pending tasks, otherwise false . |
size | Returns the current size of the queue. |
startAt | Returns the timestamp when the first task was added to the queue. If there is no tasks it returns undefined . |
softEndAt | Returns the timestamp when the soft time limit for executing tasks after the last task was added to the queue ends. If there is no tasks it returns undefined . |
hardEndAt | Returns the timestamp when the hard time limit for executing tasks forcibly ends, regardless of whether new tasks are added. If there is no tasks or the hard time limit is not active, it returns undefined . |
MIT © randajan
No vulnerabilities found.
No security vulnerabilities found.