Skip to content

Instantly share code, notes, and snippets.

@TRex22
Forked from swarajgiri/example.js
Created September 25, 2016 20:30
Show Gist options
  • Save TRex22/b3c14c7623a29c3158c27192c67e4a19 to your computer and use it in GitHub Desktop.
Save TRex22/b3c14c7623a29c3158c27192c67e4a19 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