rvagg / through2

Tiny wrapper around Node streams2 Transform to avoid explicit subclassing noise
MIT License
1.9k stars 106 forks source link

add .destroy method #25

Closed mafintosh closed 10 years ago

mafintosh commented 10 years ago

Similarly to the old through module (and many other stream modules) this adds a .destroy() method that emits close on the next tick.

This allow you to easier add teardown logic

var makeStream = function() {
  var stream = through2(...)
  stream.on('close', function() {
    // in case stream was destroyed cleanup
  })
  return stream
}

var s = makeStream()
...
s.destroy() // something went bad - destroy the stream
dominictarr commented 10 years ago

this is important if you have piped to a through2 from a classic stream.

rvagg commented 10 years ago

I don't see any objections here so I'll merge

rvagg commented 10 years ago

tried to publish as 1.0.0 but something borked (perhaps npm 2 prerelease..); so it's 1.0.1

added you as collaborator too, cheers

rvagg commented 10 years ago

oh crud, it's because I published a streams3 version of through2 as 1.0.0

that messes things up a bit, I might roll back and publish this as 0.6.0 to leave the 1.0.0 stuff intact

rvagg commented 10 years ago

what a mess, this is now 0.6.0 and there's a 1.1.0 for streams3, when 0.12 lands we can leave 0.x.x behind and go full semver