-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Doc: how to use async functions #3834
Comments
Old
New
|
I think it's a good start! We can always refine the first version later, based on user feedback.
I think it's enough to show
I think having a warning for each example would be excessive. My proposal:
@prancing-pony @strongloop/lb-next-dev Thoughts? |
Using async/awaitRemote methods can also return a promise instead of using the callback parameter. {% include code-caption.html content="/common/models/person.js" %} module.exports = function(Person){
Person.greet = async function(msg) {
return 'Greetings...';
}
Person.remoteMethod('greet', {
accepts: {arg: 'msg', type: 'string'},
returns: {arg: 'greeting', type: 'string'}
});
}; Using async/awaitOperation hooks can also return a promise instead of calling the next parameter. {% include code-caption.html content="/common/models/MyModel.js" %} MyModel.observe('before save', async function(ctx) {
//...
return
}); Using async/awaitRemote hooks can also return a promise instead of using the next parameter _modelName_.beforeRemote( _methodName_, async function( ctx) {
//...
}); This is what I propose for async examples to en/ lb3 and lb2 Remote-Methods.md, Remote-hooks and Operation-hooks.md. |
The proposal looks reasonable. Could you please open a pull request where we can iron out any remaining details? |
Closing it as resolved as PR loopbackio/loopback.io#688 has landed. |
We should enhance our documentation to show how to use async functions in the following places:
Related issues:
The text was updated successfully, but these errors were encountered: