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

stream-worker

Package Overview
Dependencies
Maintainers
3
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stream-worker

Execute an async function per stream data event, pausing the stream when a concurrency limit is saturated

  • 2.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
3
Created
Source

stream-worker build status

Execute an async function per stream data event, pausing the stream when a concurrency limit is saturated. Inspired by async.queue, optimized for streams.

Supports promises and callbacks.

The Basics

npm install stream-worker

Requiring:

var streamWorker = require('stream-worker');

Promise style:

function doWork(data){
  /* ... do some work with data ... */
  return Promise.resolve();
}
streamWorker(stream, doWork, {promises : true, concurrency : 10})
.then(function() {
  /* ... the stream is exhausted and all workers are finished ... */
}, function(err) {
  /* ... there was an error processing the stream ... */
})

Callback style:


function doWork(data, done){
  /* ... do some work with data ... */
  return done(err);;
}
streamWorker(stream, doWork, {promises : false, concurrency :10},
  function(err) {
    /* ... the stream is exhauseted and all workers are finished ... */
  }
);

Signature

streamWorker(stream, work, options, done)

Where options is an object with 2 optional parameters:

ParameterDefaultDescription
promisesfalsetrue if you want to use the above promises style
concurrency10specifies how many concurrent workers you want doing work in the stream

And done is a callback function if you use the callback workflow.

Keywords

FAQs

Package last updated on 03 Sep 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