Created
July 1, 2015 12:10
-
-
Save alekseykulikov/c63ac825e176fa650fb6 to your computer and use it in GitHub Desktop.
Wrap koa-like generators to express-like callbacks.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var co = require('co') | |
/** | |
* Wrap koa-like generators to express-like callbacks. | |
* | |
* @param {GeneratorFunction} fn | |
* @return {Function} | |
*/ | |
modules.exports = function wrap(fn) { | |
return function(req, res, next) { | |
co(function*() { | |
yield* fn(req, res) | |
}) | |
.catch(next) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment