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

Commit

Permalink
emit "end" exactly once
Browse files Browse the repository at this point in the history
  • Loading branch information
dominictarr committed Apr 24, 2013
1 parent 802ecff commit 6f814a6
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion index.js
Expand Up @@ -14,7 +14,7 @@ function through (write, end, opts) {
write = write || function (data) { this.queue(data) }
end = end || function () { this.queue(null) }

var ended = false, destroyed = false, buffer = []
var ended = false, destroyed = false, buffer = [], _ended = false
var stream = new Stream()
stream.readable = stream.writable = true
stream.paused = false
Expand All @@ -38,6 +38,9 @@ function through (write, end, opts) {
}

stream.queue = stream.push = function (data) {
// console.error(ended)
if(_ended) return stream
if(data == null) _ended = true
buffer.push(data)
drain()
return stream
Expand Down

0 comments on commit 6f814a6

Please sign in to comment.