Created
March 12, 2015 21:20
-
-
Save jeveloper/dad7a61f00d0a3443e2a to your computer and use it in GitHub Desktop.
Generators - tiny rewrite
This file contains hidden or 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
express.use(function(req, res, next){ | |
res.results = new app.results(); | |
var send = function(data){ | |
res.json(data); | |
}; | |
console.log('are we hijacking?', res.results); | |
res.results.on('error', send); | |
res.results.on('fail', send); | |
res.results.on('success', send); | |
next(); | |
}); |
This file contains hidden or 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
koa.use(function *(next){ | |
//TODO - res.results isnt available here | |
res.results = new app.results(); //TODO will need to be inject another way | |
var send = function(data){ | |
res.json(data) | |
return yield next; | |
} | |
res.results.on('error', send); | |
res.results.on('fail', send); | |
res.results.on('success', send); | |
}); | |
//i would probably rewrite results to be independent generators | |
//TODO one for success | |
//TODO one for error | |
//TODO one for fail | |
//perhaps you'd want to log events somewhere else (stream to log system) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment