New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

es.concat - if any stream is ended it doesn't work #41

Closed
manuelsantillan opened this Issue Nov 23, 2013 · 1 comment

Comments

Projects
None yet
3 participants
@manuelsantillan

manuelsantillan commented Nov 23, 2013

If passing an already ended stream to es.concat / es.merge, it won't work unless an "end" event is manually provoked for that stream.

A possible fix would be to check if there is a "ended" property in the stream object and increment the counter during stream registration:

es.merge = function (/streams.../) {
var toMerge = [].slice.call(arguments)
var stream = new Stream()
var endCount = 0
stream.writable = stream.readable = true

toMerge.forEach(function (e) {

e.pipe(stream, {end: false})
var ended = false
  //BEGIN FIX
if(e.ended) {
    ended=true
    endCount++
}
  //END FIX
e.on('end', function () {

    if(ended) return
  ended = true
  endCount ++
  if(endCount == toMerge.length)
    stream.emit('end') 
})

})
stream.write = function (data) {
this.emit('data', data)
}
stream.destroy = function () {
merge.forEach(function (e) {
if(e.destroy) e.destroy()
})
}
return stream
}

manuelsantillan added a commit to manuelsantillan/event-stream that referenced this issue Nov 23, 2013

@dominictarr

This comment has been minimized.

Owner

dominictarr commented Nov 25, 2013

There is no standand way to indicate that a stream has already ended, so it's unlikely this patch would work in general.

How are you getting streams that have already ended?
prehaps there is another approach to your problem.
can you explain/post code that shows what you are trying to do?

@right9ctrl right9ctrl closed this Sep 6, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment