https://github.com/jamen/pull-drain-cont
Pull stream sink that drains source stream's data
https://github.com/jamen/pull-drain-cont
Last synced: about 1 year ago
JSON representation
Pull stream sink that drains source stream's data
- Host: GitHub
- URL: https://github.com/jamen/pull-drain-cont
- Owner: jamen
- License: mit
- Created: 2017-01-20T07:29:18.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-01-20T07:45:34.000Z (over 9 years ago)
- Last Synced: 2025-03-18T00:33:14.495Z (about 1 year ago)
- Language: JavaScript
- Size: 7.81 KB
- Stars: 3
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# pull-drain
> Pull stream sink that drains source stream's data
A [pull stream](https://github.com/pull-stream/pull-stream) sink that calls function for each data in the stream.
```js
pull(
values(1, 2, 3),
map(x => x * 2),
drain(x => console.log(x))
)(function (err) {
// Finished
})
```
**Note:** This is a [continuable](https://github.com/pull-stream/pull-stream/pull/89).
## Installation
```sh
$ npm install --save pull-drain
```
## Usage
### `drain(op)`
Drain stream data, calling `op` for each read.
```js
pull(
count(50),
map(x => [x, x % 2 === 0])
drain(x => console.log(x))
)(function (err) {
// Finished
})
// No callback:
pull(
...streams,
drain(x => console.log(x))
)()
```
Return `false` inside the `op` function to abort the stream.
### `sink.abort([err])`
To abort the stream from outside the callback, you can use an `.abort` method, and optionally pass it an error:
```js
var drainer = drain(function (item) {
// ...
})
if (foo) {
drainer.abort(new Error('Foo!'))
}
pull(
infinity(),
drainer
)(function (err) {
// You got an error!
})
```
## License
MIT © [Jamen Marz](https://git.io/jamen)
---
[][package] [](https://travis-ci.org/jamen/pull-drain) [][package] [][package] [](https://paypal.me/jamenmarz/5usd) [](https://github.com/jamen)
[package]: https://npmjs.org/package/pull-drain