finished
Advanced tools
Comparing version 1.1.3 to 1.1.4
@@ -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) |
{ | ||
"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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
3848
20
83
4
1