caco-express
v1.0.0
Published
Express middleware wrapper using caco generator function
Downloads
4
Readme
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) {
// yield callback function using caco next(err, val)
req.data = yield fs.readFile('./data.json', 'utf8', next)
yield setTimeout(next, 10)
next() // calling next() passes to next middleware
}, function * (req, res) {
res.send(data)
}))
// 4 arguments for error handling middleware
app.use(wrap(function * (err, req, res, next) {
res.status(500).send({
success: false,
message: err.message
})
}))
License
MIT