https://github.com/nodesource/rapid-stream
Through stream that processes elements in parallel, with no regard for input order.
https://github.com/nodesource/rapid-stream
Last synced: 8 months ago
JSON representation
Through stream that processes elements in parallel, with no regard for input order.
- Host: GitHub
- URL: https://github.com/nodesource/rapid-stream
- Owner: nodesource
- License: other
- Archived: true
- Created: 2015-06-16T17:09:49.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2015-06-16T17:10:07.000Z (over 10 years ago)
- Last Synced: 2025-04-13T07:45:32.222Z (9 months ago)
- Language: JavaScript
- Size: 97.7 KB
- Stars: 8
- Watchers: 10
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# rapid-stream




Through stream that processes elements in parallel, with no regard for input order.
Similar to [parallel-transform](http://github.com/mafintosh/parallel-transform),
however because it ignores input order it can process input faster when incoming
chunks take a variable amount of time to resolve, e.g. network requests behind
a caching layer.
## Usage
[](https://nodei.co/npm/rapid-stream/)
### `rapid(parallelism, [opts], handle)`
Creates a new rapid stream that will handle at most `parallelism` chunks at any one
time. Optionally, you may pass in `opts` to override the default stream options.
Note that this is an object mode stream by default.
`handle(chunk, encoding, next)` is called for each incoming chunk, and works more
or less the same as it does in [through2](http://github.com/rvagg/through2).
``` javascript
const RapidStream = require('rapid-stream')
const from2 = require('from2')
var stream = RapidStream(2, function(chunk, encoding, next) {
setTimeout(function() {
next(null, chunk)
}, 1000 * Math.random())
})
from2([1, 2, 3, 4, 5]).pipe(stream).on('data', function(data) {
console.log(data)
})
// 2
// 1
// 3
// 5
// 4
```
## License
MIT. See [LICENSE.md](http://github.com/nodesource/rapid-stream/blob/master/LICENSE.md) for details.