Socket
Socket
Sign inDemoInstall

fastq

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fastq

Fast, in memory work queue


Version published
Weekly downloads
39M
decreased by-1.37%
Maintainers
1
Weekly downloads
 
Created

What is fastq?

The fastq npm package is a fast, in-memory queue with worker functions. It is useful for managing tasks and processing them concurrently with a controlled level of parallelism. It allows you to define tasks, add them to the queue, and process them with a defined concurrency level.

What are fastq's main functionalities?

Task Queueing

This feature allows you to create a queue with a worker function that processes tasks. The second argument to `fastq` is the concurrency level, which in this case is set to 2, meaning that up to two tasks can be processed in parallel.

const fastq = require('fastq');
const worker = (task, cb) => {
  console.log(`Processing task: ${task}`);
  cb();
};
const queue = fastq(worker, 2);
queue.push('task1', (err) => console.log('Finished processing task1'));
queue.push('task2', (err) => console.log('Finished processing task2'));

Pause and Resume

This feature allows you to pause the processing of tasks in the queue and resume it later. This can be useful for throttling or when the system needs to perform other high-priority operations.

const fastq = require('fastq');
const worker = (task, cb) => {
  setTimeout(() => {
    console.log(`Processed: ${task}`);
    cb();
  }, 1000);
};
const queue = fastq(worker, 1);
queue.push('task1');
queue.push('task2');
queue.pause();
// ... some time later
queue.resume();

Drain Event

The 'drain' event is emitted when the last item from the queue has been assigned to a worker. It can be used to know when all tasks have been processed and the queue is empty.

const fastq = require('fastq');
const worker = (task, cb) => {
  console.log(`Processing task: ${task}`);
  cb();
};
const queue = fastq(worker, 2);
queue.drain = () => {
  console.log('All tasks have been processed');
};
queue.push('task1');
queue.push('task2');

Other packages similar to fastq

Keywords

FAQs

Package last updated on 01 Apr 2020

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc