Socket
Socket
Sign inDemoInstall

finished

Package Overview
Dependencies
0
Maintainers
6
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.1.3 to 1.1.4

7

index.js

@@ -0,1 +1,6 @@

var defer = typeof setImmediate === 'function'
? setImmediate
: process.nextTick
module.exports = function (thingie, callback) {

@@ -5,3 +10,3 @@ var socket = thingie.socket || thingie

if (!socket.writable)
return setImmediate(callback)
return defer(callback)

@@ -8,0 +13,0 @@ socket.on('error', done)

5

package.json
{
"name": "finished",
"description": "Execute a callback when a request closes, finishes, or errors",
"version": "1.1.3",
"version": "1.1.4",
"author": {

@@ -24,2 +24,5 @@ "name": "Jonathan Ong",

},
"engine": {
"node": ">= 0.8.0"
},
"scripts": {

@@ -26,0 +29,0 @@ "test": "mocha --require should --reporter spec"

@@ -1,14 +0,36 @@

# finished [![Build Status](https://travis-ci.org/expressjs/finished.png)](https://travis-ci.org/expressjs/finished)
# finished [![Build Status](https://travis-ci.org/expressjs/finished.svg?branch=master)](https://travis-ci.org/expressjs/finished) [![NPM Version](https://badge.fury.io/js/finished.svg)](http://badge.fury.io/js/finished)
Execute a callback when a request closes, finishes, or errors. This is useful for cleaning up streams. For example, you want to destroy any file streams you create on socket errors otherwise you will leak file descriptors.
Execute a callback when a request closes, finishes, or errors.
#### Install
`npm install finished`
#### Uses
This is useful for cleaning up streams. For example, you want to destroy any file streams you create on socket errors otherwise you will leak file descriptors.
This is required to fix what many perceive as issues with node's streams. Relevant:
- https://github.com/joyent/node/issues/6041
- https://github.com/koajs/koa/issues/184
- https://github.com/koajs/koa/issues/165
- [node#6041](https://github.com/joyent/node/issues/6041)
- [koa#184](https://github.com/koajs/koa/issues/184)
- [koa#165](https://github.com/koajs/koa/issues/165)
## API
### finished(response, callback)
```js
var onFinished = require('finished')
onFinished(res, function (err) {
// do something maybe
})
```
### Examples
The following code ensures that file descriptors are always closed once the response finishes.
Node / Connect / Express:
#### Node / Connect / Express

@@ -27,3 +49,3 @@ ```js

Koa:
#### Koa

@@ -61,2 +83,2 @@ ```js

OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
THE SOFTWARE.

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc