Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
@sapphire/async-queue
@sapphire/async-queue is a utility for managing asynchronous tasks in a sequential manner. It ensures that tasks are executed one after another, preventing race conditions and ensuring order.
Basic Queue Usage
This code demonstrates the basic usage of @sapphire/async-queue. It creates a queue and ensures that task1 and task2 are executed sequentially.
const { AsyncQueue } = require('@sapphire/async-queue');
const queue = new AsyncQueue();
async function task1() {
await queue.wait();
console.log('Task 1 started');
setTimeout(() => {
console.log('Task 1 completed');
queue.shift();
}, 1000);
}
async function task2() {
await queue.wait();
console.log('Task 2 started');
setTimeout(() => {
console.log('Task 2 completed');
queue.shift();
}, 500);
}
task1();
task2();
Handling Errors in Queue
This code demonstrates how to handle errors within the queue. Even if a task throws an error, the queue continues to process the next task.
const { AsyncQueue } = require('@sapphire/async-queue');
const queue = new AsyncQueue();
async function taskWithError() {
await queue.wait();
console.log('Task with error started');
setTimeout(() => {
console.log('Task with error encountered an error');
queue.shift();
throw new Error('Task error');
}, 1000);
}
async function taskAfterError() {
await queue.wait();
console.log('Task after error started');
setTimeout(() => {
console.log('Task after error completed');
queue.shift();
}, 500);
}
taskWithError().catch(console.error);
taskAfterError();
The 'async' package provides a wide range of utilities for working with asynchronous JavaScript. It includes functions for parallel and sequential execution, among others. Compared to @sapphire/async-queue, 'async' offers more comprehensive functionality but can be more complex to use for simple sequential task management.
The 'p-queue' package is a promise queue with concurrency control. It allows you to manage the execution of promises with a specified concurrency level. While 'p-queue' offers more advanced features like concurrency control, @sapphire/async-queue focuses on simple sequential execution.
The 'queue' package is a simple and efficient queue implementation for Node.js. It supports basic queue operations and is easy to use. Compared to @sapphire/async-queue, it lacks built-in support for asynchronous task management but can be extended for such use cases.
FAQs
Sequential asynchronous lock-based queue for promises
We found that @sapphire/async-queue demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.