use on-socket-error

This commit is contained in:
Jonathan Ong 2013-12-20 14:39:53 -08:00
parent 02409b9d5d
commit 879293f548
4 changed files with 4 additions and 17 deletions

View file

@ -2,6 +2,7 @@ HEAD
================== ==================
* update co * update co
* use on-socket-error
0.1.1 / 2013-12-19 0.1.1 / 2013-12-19
================== ==================

View file

@ -3,6 +3,7 @@
*/ */
var debug = require('debug')('koa:application'); var debug = require('debug')('koa:application');
var onSocketError = require('on-socket-error');
var Emitter = require('events').EventEmitter; var Emitter = require('events').EventEmitter;
var compose = require('koa-compose'); var compose = require('koa-compose');
var context = require('./context'); var context = require('./context');
@ -99,7 +100,7 @@ app.callback = function(){
return function(req, res){ return function(req, res){
var ctx = self.createContext(req, res); var ctx = self.createContext(req, res);
ctx.onSocketError(ctx.onerror); onSocketError(ctx, ctx.onerror);
fn.call(ctx, ctx.onerror); fn.call(ctx, ctx.onerror);
} }
}; };

View file

@ -488,20 +488,4 @@ module.exports = {
attachment: function() { attachment: function() {
return this.response.attachment.apply(this.response, arguments); return this.response.attachment.apply(this.response, arguments);
}, },
/**
* Invoke `fn` on socket errors and
* handle cleanup on response.
*
* @param {Function} fn
* @api private
*/
onSocketError: function(fn){
var sock = this.socket;
sock.once('error', fn);
this.res.on('finish', function(){
sock.removeListener('error', fn);
});
}
}; };

View file

@ -21,6 +21,7 @@
], ],
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"on-socket-error": "~1.0.0",
"co": "~3.0.0", "co": "~3.0.0",
"debug": "*", "debug": "*",
"mime": "~1.2.11", "mime": "~1.2.11",