Skip to content

Instantly share code, notes, and snippets.

@swarajgiri
Created July 14, 2015 07:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save swarajgiri/16202e32aa4d80d45c62 to your computer and use it in GitHub Desktop.
Save swarajgiri/16202e32aa4d80d45c62 to your computer and use it in GitHub Desktop.
example
function mySexyMethod() {
return new Promise(function (resolve, reject) {
someAsync.method(params, function (err, data) {
if (err) {
return reject(err);
}
resolve(data);
})
});
}
### Express router
var wrap = require('co-express');
router.verb('some-route', wrap(function* (req, res, next) {
var val;
try {
val = yield mySexyMethod();
} catch (e) {
return next(e);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment