caco-express
Express middleware wrapper for caco generator function.
npm install caco-express
This is a caco version of co-express,
which supports 'yielding' callback functions using next(err, val)
.
Calling next()
without argument, passes control to the next middleware stack.
var express = require('express')
var wrap = require('caco-express')
var fs = require('fs')
var app = express()
app.get('/foo', wrap(function * (req, res, next) {
req.data = yield fs.readFile('./data.json', 'utf8', next)
yield setTimeout(next, 10)
next()
}, function * (req, res) {
res.send(data)
}))
app.use(wrap(function * (err, req, res, next) {
res.status(500).send({
success: false,
message: err.message
})
}))
License
MIT