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
Make queries compatible with koa and yield keyword #1859
Comments
Haven't tried it but I'm guessing that the following works:
Can you confirm? |
what about Maybe I'm missing something, but to make it work i need to do: var thunk = require('thunkify')
// ...
document.save = thunk(document.save)
document = yield document.save() |
@flockonus save() doesn't return a promise yet, but it will in 3.10. See #1431 |
The current most "native" workaround: model.js
routes.js
|
@bodokaiser did you get your code working? I get an error:Error: yield a function, promise, generator, array, or object |
@bodokaiser no error but it looks like yield is never resolved |
@paglias yeah checkout #1812 (comment) |
@bodokaiser thanks, actually I wasn't running |
yeah generators are still somehow experimental. I also got some cases where I get undefined thrown as error and no idea where it comes from (though not from l´koa) |
@bodokaiser it was my fault, totally :) Anyway I'm using schema.method('persist', thunkify(function(){
return this.save.apply(this, arguments);
})); To avoid having to call it twice: |
If you use my plugin as linked than you also do not have to use it twice + no dependences + workable on all models :)
use with |
@bodokaiser You have a typo in your last code. Thanks will try that. |
|
Since thunks are on the way out of
|
According to this article it is not possible to use mongoose with yield keyword to get rid of callbacks. Could this be addressed in Mongoose 4.0.0?
The text was updated successfully, but these errors were encountered: