Skip to content

Commit

Permalink
deps: destroy@1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dougwilson committed Mar 21, 2022
1 parent 6060bda commit aee1a65
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 16 deletions.
2 changes: 1 addition & 1 deletion HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ unreleased
* deps: depd@2.0.0
- Replace internal `eval` usage with `Function` constructor
- Use instance methods on `process` to check for listeners
* deps: destroy@1.1.1
* deps: destroy@1.2.0
* deps: http-errors@2.0.0
- deps: depd@2.0.0
- deps: statuses@2.0.1
Expand Down
24 changes: 10 additions & 14 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -785,8 +785,6 @@ SendStream.prototype.sendIndex = function sendIndex (path) {
*/

SendStream.prototype.stream = function stream (path, options) {
// TODO: this is all lame, refactor meeee
var finished = false
var self = this
var res = this.res

Expand All @@ -795,20 +793,18 @@ SendStream.prototype.stream = function stream (path, options) {
this.emit('stream', stream)
stream.pipe(res)

// response finished, done with the fd
onFinished(res, function onfinished () {
finished = true
destroy(stream)
})
// cleanup
function cleanup () {
destroy(stream, true)
}

// error handling code-smell
stream.on('error', function onerror (err) {
// request already finished
if (finished) return
// response finished, cleanup
onFinished(res, cleanup)

// clean up stream
finished = true
destroy(stream)
// error handling
stream.on('error', function onerror (err) {
// clean up stream early
cleanup()

// error
self.onStatError(err)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"dependencies": {
"debug": "2.6.9",
"depd": "2.0.0",
"destroy": "1.1.1",
"destroy": "1.2.0",
"encodeurl": "~1.0.2",
"escape-html": "~1.0.3",
"etag": "~1.8.1",
Expand Down

0 comments on commit aee1a65

Please sign in to comment.