Skip to content
This repository has been archived by the owner on Nov 28, 2018. It is now read-only.

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

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

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

manuelsantillan opened this issue Nov 23, 2013 · 1 comment

Comments

@manuelsantillan
Copy link

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
Copy link
Owner

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?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@dominictarr @manuelsantillan and others