![Introducing Enhanced Alert Actions and Triage Functionality](https://cdn.sanity.io/images/cgdhsj6q/production/fe71306d515f85de6139b46745ea7180362324f0-2530x946.png?w=800&fit=max&auto=format)
Product
Introducing Enhanced Alert Actions and Triage Functionality
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
queue-promise
Advanced tools
Readme
queue-promise
is a small, dependency-free library for promise-based queues. It will resolve enqueued functions concurrently at a given speed. When a task is being resolved or rejected, an event will be emitted.
$ npm install queue-promise
import Queue from "queue-promise";
const queue = new Queue({
concurrent: 1, // resolve 1 task at a time
interval: 2000, // resolve new tasks each 2000ms,
start: true, // automatically resolve new tasks when they are added
});
queue.on("resolve", data => console.log(data));
queue.on("reject", error => console.error(error));
queue.enqueue(asyncTaskA); // resolved/rejected after 0s
queue.enqueue(asyncTaskB); // resolved/rejected after 2s
queue.enqueue(asyncTaskC); // resolved/rejected after 4s
queue.enqueue(asyncTaskD); // resolved/rejected after 6s
new Queue(options)
Create a new Queue
instance.
Option | Default | Description |
---|---|---|
concurrent | 5 | How many tasks can be handled at the same time |
interval | 500 | How often should new tasks be handled (in ms) |
start | true | Whether we should automatically resolve new tasks as soon as they are added |
.enqueue(task)
/.add(task)
Puts a new task on the stack. Tasks should be an async function or return a promise. Throws an error if the provided task
is not a valid function.
Example:
async function getRepos(user) {
return await github.getRepos(user);
};
queue.enqueue(getRepos("userA"));
queue.enqueue(getRepos("userB"));
// …equivalent to:
queue.enqueue([
getRepos("userA"),
getRepos("userB"),
]);
.dequeue()
Resolves n concurrent promises from the queue. Uses global Promises.
Example:
queue.enqueue(getRepos("userA"));
queue.enqueue(getRepos("userB"));
// If "concurrent" is set to 1, only one promise is resolved on dequeue:
const userA = await queue.dequeue();
const userB = await queue.dequeue();
// If "concurrent" is set to 2, two promises are resolved concurrently:
const users = await queue.dequeue();
.on(event, callback)
Sets a callback
for an event
. You can set callback for those events: start
, stop
, resolve
, reject
, end
.
Example:
queue.enqueue([…]);
queue.on("resolve", output => …);
queue.on("reject", output => …);
queue.on("end", () => …);
.start()
Starts the queue – it will automatically dequeue tasks periodically. Emits start
event.
.stop()
Stops the queue. Emits stop
event.
.clear()
Removes all tasks from the queue.
.started
Whether the queue has been started or not.
.isEmpty
Whether the queue is empty, i.e. there's no tasks.
$ npm test
FAQs
A simple, dependency-free library for concurrent promise-based queues. Comes with with concurrency and timeout control.
The npm package queue-promise receives a total of 12,558 weekly downloads. As such, queue-promise popularity was classified as popular.
We found that queue-promise demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
Security News
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
Security News
OpenSSF is warning open source maintainers to stay vigilant against reputation farming on GitHub, where users artificially inflate their status by manipulating interactions on closed issues and PRs.