Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

batch

Package Overview
Dependencies
Maintainers
2
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

batch

Simple async batch with concurrency control and progress reporting.

  • 0.6.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
9M
decreased by-29.57%
Maintainers
2
Weekly downloads
 
Created

What is batch?

The 'batch' npm package is a utility that allows for batch processing of jobs, where jobs can be executed in parallel or serially. It is useful for managing and controlling the execution of multiple tasks at once, with features such as concurrency control, error handling, and event listening.

What are batch's main functionalities?

Batch Processing

This code sample demonstrates how to create a batch of jobs with a concurrency of 2, meaning two jobs will be processed at a time. It also shows how to listen for progress events and handle the completion of all jobs.

const Batch = require('batch');
const batch = new Batch();

batch.concurrency(2);

batch.push(function(done) {
  setTimeout(function() {
    console.log('Job 1 done');
    done();
  }, 1000);
});

batch.push(function(done) {
  setTimeout(function() {
    console.log('Job 2 done');
    done();
  }, 500);
});

batch.on('progress', function(e) {
  console.log(e.percent + '% complete');
});

batch.end(function(err, results) {
  console.log('All jobs completed');
});

Error Handling

This code sample demonstrates how to handle errors within a batch. If any job calls the 'done' callback with an error, the 'end' event will receive this error, allowing for centralized error handling.

const Batch = require('batch');
const batch = new Batch();

batch.push(function(done) {
  // Simulate an error
  done(new Error('Something went wrong'));
});

batch.end(function(err, results) {
  if (err) {
    console.error('Error encountered:', err.message);
  }
  console.log('Results:', results);
});

Other packages similar to batch

FAQs

Package last updated on 16 May 2017

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