
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
@xtia/async-queue
Advanced tools
A lightweight but powerful asynchronous task queuing system, with smart task priority and configurable concurrency limit
A lightweight but powerful asynchronous task queuing system, with smart task priority and configurable concurrency limit.
npm i @xtia/async-queue
import { AsyncQueue } from "@xtia/async-queue";
// create a queue with default options
// (maxConcurrent = 1)
const queue = new AsyncQueue();
// enqueue a task with a Promise-like interface:
// (enqueue() returns a promise that forwards the task's resolution)
const text = await queue.enqueue<Response>(resolve => {
fetch(someUrl).then(resolve);
}).then(r => r.text());
// enqueue a task with a specific priority:
queue.enqueue(resolve => {
someAsyncOperation().then(resolve);
}, 1);
As well as resolution, promise rejection is forwarded by enqueue:
queue.enqueue((resolve, reject) => {
fetch("doesntexist.lol").then(resolve, reject);
}).catch((err) => console.warn("fetch failed:", err));
queue.createFunc()createFunc(fn, priority?) lets us easily convert asynchronous functions to identically-signed functions that place their behaviour in the queue.
const queue = new AsyncQueue({
maxConcurrent: 3, // allow 3 notifications to be shown at a time
});
// we have a normal function to show a notification
function showNotification(level: "info" | "warning", message: string) {
return new Promise(resolve => {
// ... code to show notification
// resolve when removed by click or timeout
});
}
// wrap it so that its behaviour is queued when called
export const enqueueNotification = queue.createFunc(showNotification);
// function's signature is maintained, but calls are automatically enqueued:
enqueueNotification("info", "Download complete");
When wrapping the function, we can provide a priority for that function, or a function to determine a call's priority from its arguments:
// prioritise warnings
export const enqueueNotification = queue.createFunc(
showNotification,
(level, message) => level == "warning" ? 1 : 2
);
AsyncQueue's constructor can be passed an object with the following properties
maxConcurrent: numberSpecifies how many tasks can be processed at a time. Default is 1.
defaultPriority: numberSpecifies a standard priority. Default is 5.
delayMs: numberSpecifies a delay between a queued task's completion and its concurrency slot becoming available for another task. Default is 0.
FAQs
A lightweight but powerful asynchronous task queuing system, with smart task priority and configurable concurrency limit
The npm package @xtia/async-queue receives a total of 0 weekly downloads. As such, @xtia/async-queue popularity was classified as not popular.
We found that @xtia/async-queue demonstrated a healthy version release cadence and project activity because the last version was released less than 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.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.