Skip to content

Commit

Permalink
Add generator support to the middleware stack
Browse files Browse the repository at this point in the history
  • Loading branch information
kenrick committed Jan 19, 2015
1 parent 40f7a8e commit 8dac72b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
5 changes: 5 additions & 0 deletions lib/router/layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

var pathRegexp = require('path-to-regexp');
var debug = require('debug')('express:router:layer');
var co = require('co');

/**
* Module variables.
Expand Down Expand Up @@ -73,6 +74,10 @@ Layer.prototype.handle_error = function handle_error(error, req, res, next) {
Layer.prototype.handle_request = function handle(req, res, next) {
var fn = this.handle;

if(fn.constructor.name === 'GeneratorFunction') {
fn = co.wrap(fn);
}

if (fn.length > 3) {
// not a standard request handler
return next();
Expand Down
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
],
"dependencies": {
"accepts": "~1.2.2",
"co": "^4.1.0",
"content-disposition": "0.5.0",
"cookie": "0.1.2",
"cookie-signature": "1.0.5",
"debug": "~2.1.1",
"depd": "~1.0.0",
Expand All @@ -37,6 +39,7 @@
"finalhandler": "0.3.3",
"fresh": "0.2.4",
"media-typer": "0.3.0",
"merge-descriptors": "0.0.2",
"methods": "~1.1.1",
"on-finished": "~2.2.0",
"parseurl": "~1.3.0",
Expand All @@ -47,10 +50,8 @@
"send": "0.11.0",
"serve-static": "~1.8.0",
"type-is": "~1.5.5",
"vary": "~1.0.0",
"cookie": "0.1.2",
"merge-descriptors": "0.0.2",
"utils-merge": "1.0.0"
"utils-merge": "1.0.0",
"vary": "~1.0.0"
},
"devDependencies": {
"after": "0.8.1",
Expand Down

1 comment on commit 8dac72b

@Fonger
Copy link

@Fonger Fonger commented on 8dac72b Apr 4, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't catch the error here. If there's an error in the generator function, it will disappear and end up timeout.

Please sign in to comment.