Options
All
  • Public
  • Public/Protected
  • All
Menu

combine-evented-stream — Reference

Combine Evented Stream

Combine multiple evented streams into one

Usage Examples

Log output of multiple child processes

const { spawn } = require('child_process')
const combine = require('combine-evented-stream')

const cps = [
  'foo',
  'bar',
  'baz'
].map(program => spawn(program))

const stream = combine(cps)

stream.addListener('data', ({ stream, chunk }) => {
  console.log({
    pid: stream.pid,
    data: chunk
  })
})

stream.addListener('close', () => {
  console.log('done.')
  return process.exit(0)
})

Utilize iterate-evented-stream:

Assuming the context of execution below is async.

const { spawn } = require('child_process')
const combine = require('combine-evented-stream')
const iterate = require('iterate-evented-stream')

const cps = [
  'foo',
  'bar',
  'baz'
].map(program => spawn(program))

const stream = combine(cps)

for await (const { stream, chunk } of iterate(stream)) {
  console.log({
    pid: stream.pid,
    data: chunk
  })
}

console.log('done.')

License

MIT © Hoàng Văn Khải

Generated using TypeDoc