0.1.1 • Published 7 years ago

pull-drain v0.1.1

Weekly downloads
3
License
MIT
Repository
github
Last release
7 years ago

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


version travis downloads license support me follow