co icon indicating copy to clipboard operation
co copied to clipboard

Add streams into yieldable list

Open andreytkachenko opened this issue 6 years ago • 2 comments

Hi, I think it will be nice to be able yielding the streams (it will be waiting the stream "end" event) as well.

andreytkachenko avatar Apr 26 '18 13:04 andreytkachenko

@andreytkachenko Can you elaborate more ?

IdpugantiSanjay avatar Mar 11 '20 10:03 IdpugantiSanjay

Current yieldable list are:

  • promises
  • thunks (functions)
  • array (parallel execution)
  • objects (parallel execution)
  • generators (delegation)
  • generator functions (delegation) I am suggesting add streams in that list as well. It is possible to promisify stream like that:
const promisify = (readable) => {
  const result = []
  const w = new Writable({
    write(chunk, encoding, callback) {·
      result.push(chunk)
      callback()
    }
  })
  readable.pipe(w)
  return new Promise((resolve, reject) => {
    w.on('finish', resolve)
    w.on('error', reject)
  }).then(() => result.join(''))
}

and then yield them, but it would be great to just yield them

andreytkachenko avatar Mar 11 '20 11:03 andreytkachenko