-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
using with KOA, Generators, Yield #2177
Comments
I heard it's planned for 4.0 I'm using mongoose 3.8 with a small plugin to make save/remove work with yield. |
So 3.9, which is unstable, right now has support for yield .save(), .validate(). Once 4.0 comes out that'll be stable :) |
Hi, On Mon, Jul 7, 2014 at 1:48 PM, Ilya Kantor notifications@github.com
Sincerely yours |
@vkarpov15 do you think is/will be possible to use generators in hooks? |
@paglias can you provide an example of what you're looking to do? |
@vkarpov15 I think I've read somewhere that you plan to change the hook system in 4.0 so maybe it can be fixed there but now in order to use a generator inside an hook I use something like that: userSchema.pre('save', function(next){
co(function *(){
try{
yield something here....
next();
}catch(err){
next(err);
}
}).call(this);
}); Which isn't really nice. I would like the ability to supply a generator directly to the hook instead of having to call Also not exectly related to this but I've noticed that if I don't add an empty listener to Anyway just adding something like that is enough:
Thanks for the help! |
@vkarpov15 I think the error propagation is due to:
And using exec() instead of the callback it passes the error to the connection |
@paglias that's a good suggestion, but I don't really foresee that happening in the near future, at least until ES6 is way more widely used than it is today. I don't really see a way to do that without breaking compatibility with 0.10.x. |
+1 for koa support ;)... |
Maybe bluebird is a simple way for 3.8. var Promise = require('bluebird');
var mongoose = Promise.promisifyAll(require('mongoose'));
app.use(function * () {
var user = yield User.findOneAsync();
this.body = user.email;
}); |
Thanks @cncolder. |
@xpepermint bluebird is only a solution for mongoose 3.8.x I love new feature too. In fact. I had trying traceur in a small personal project. Write nearly all es6 style code. Even async function in es7. mongoose 3.9.2 has browserify bundle-able. Nobody care this new feature? |
Using Mongoose 3.9.x you have I'm using it in a Koa application and it works very well |
What a coincidence! I've just finished a Mongoose DAO class which support promise (Q): Updated: with that implementation, now I can do like this: app.get('/users', function *(next) {
var users = yield Users.findAll();
this.body = users;
}); |
Hi,
KOA is spreading fast, but we can not use mongoose with it, because lack of generator support in mongoose, do we have to wait for next versions, is it planned? or any solution?
Thanks
The text was updated successfully, but these errors were encountered: