combine-evented-stream
TypeScript icon, indicating that this package has built-in type declarations

0.1.8 • Public • Published

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

Package Sidebar

Install

npm i combine-evented-stream

Weekly Downloads

0

Version

0.1.8

License

MIT

Unpacked Size

10.1 kB

Total Files

17

Last publish

Collaborators

  • khai96_