pull-drain
v0.1.1
Published
Pull stream sink that drains source stream's data
Downloads
5
Readme
pull-drain
Pull stream sink that drains source stream's data
A pull stream sink that calls function for each data in the stream.
pull(
values(1, 2, 3),
map(x => x * 2),
drain(x => console.log(x))
)(function (err) {
// Finished
})
Note: This is a continuable.
Installation
$ npm install --save pull-drain
Usage
drain(op)
Drain stream data, calling op
for each read.
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.
drain(op).abort([err])
To abort the stream from outside the callback, you can use an .abort
method, and optionally pass it an error:
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