Skip to content

Instantly share code, notes, and snippets.

@alekseykulikov
Created July 1, 2015 12:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alekseykulikov/c63ac825e176fa650fb6 to your computer and use it in GitHub Desktop.
Save alekseykulikov/c63ac825e176fa650fb6 to your computer and use it in GitHub Desktop.
Wrap koa-like generators to express-like callbacks.
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