# stream-worker

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

Latest version **2.0.2** (published 2020-09-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install stream-worker
pnpm add stream-worker
yarn add stream-worker
bun add stream-worker
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.2 |
| Published | 2020-09-03 |
| First published | 2013-08-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | ~0.10.0 |
| Dependencies | 1 |
| Unpacked size | 10 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 12 |
| Author | Good Eggs |
| Maintainers | goodeggs-admin, hurrymaplelad, sylspren |
| Keywords | stream, worker, async, queue |

## Links

- npm: https://www.npmjs.com/package/stream-worker
- Repository: https://github.com/goodeggs/stream-worker
- Homepage: https://github.com/goodeggs/stream-worker#readme
- Issues: https://github.com/goodeggs/stream-worker/issues
- npm.io page: https://npm.io/package/stream-worker

## Dependencies (1)

- [bluebird](https://npm.io/package/bluebird.md) ^3.1.1

## Alternatives

- [cron](https://npm.io/package/cron.md) — 4.9M weekly downloads
- [@vercel/queue](https://npm.io/package/@vercel/queue.md) — 731.6K weekly downloads
- [create-sonicjs](https://npm.io/package/create-sonicjs.md) — 1.6K weekly downloads
- [@exellix/jobs-api](https://npm.io/package/@exellix/jobs-api.md) — 941 weekly downloads
- [@forwardimpact/libskill](https://npm.io/package/@forwardimpact/libskill.md) — 575 weekly downloads

## Recent versions

- 2.0.2 (latest) — 2020-09-03
- 2.0.1 — 2016-07-18
- 2.0.0 — 2016-06-09
- 1.0.2 — 2016-04-28
- 1.0.1 — 2016-03-22
- 1.0.0 — 2016-01-05
- 0.0.1 — 2013-08-21
- 0.0.0 — 2013-08-07

## README

stream-worker  [![build status](https://secure.travis-ci.org/goodeggs/stream-worker.png)](http://travis-ci.org/goodeggs/stream-worker)
=============

Execute an async function per [stream](http://nodejs.org/api/stream.html) data event, pausing the stream when a concurrency limit is saturated.  Inspired by [async.queue](https://github.com/caolan/async#queue), optimized for streams.

Supports promises and callbacks.


The Basics
----------

```
npm install stream-worker
```

Requiring:

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


Promise style:
```js
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:

```js

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:

| Parameter     | Default       | Description|
|------------- |-------------| -----|
| promises      |false| true if you want to use the above promises style|
| concurrency| 10|specifies how many concurrent workers you want doing work in the stream |

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

---
_Source: https://npm.io/package/stream-worker · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
