bustle / bluestream

A collection of streams that work well with promises (through, map, reduce). Think Through2 with promises
MIT License
103 stars 5 forks source link

Stream Ending Early #22

Closed southpolesteve closed 7 years ago

southpolesteve commented 7 years ago

Fast stream piped to slow stream seems to be ending early

const bluestream = require('bluestream')

let begin = 0
let end = 100

const idStream = bluestream.read(async function () {
  if (begin < end) {
    begin++
    this.push(begin)
  } else {
    return null
  }
})

const articleStream = bluestream.transform({ concurrent: 20 }, function (id) {
  return new Promise((resolve) => {
    setTimeout(() => {
      console.log('resolved', id)
      resolve(id)
    }, 100)
  })
})

bluestream.pipe(idStream, articleStream).then(console.log, console.log)
setTimeout(() => console.log('Done!'), 10000)

Try adjusting concurrent and also the setTImeout length and you'll get different results. In any case I can't get all 100 numbers to print. It always ends early.

reconbot commented 7 years ago

The transform stream's buffer is getting full and so it stops the flow until it gets read, either use a write stream or read the transform stream