question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[NodeJS] Promises and async/await

See original GitHub issue

It would be nice if there was a grpc-tools and/or grpc_node_plugin option that would generate client and server code that follows the ES6 Promise and ES7 async/await model.

For example, instead of: https://github.com/grpc/grpc/blob/98f8989a6712118549c432c9f91b6a516250014d/examples/node/static_codegen/greeter_client.js#L35-L37 We could write:

  [err, response] = await client.sayHello(request);

Or something similar. On the server side, instead of: https://github.com/grpc/grpc/blob/98f8989a6712118549c432c9f91b6a516250014d/examples/node/static_codegen/greeter_server.js#L27-L31 We could write:

async function sayHello(call) {
  var reply = new messages.HelloReply();
  reply.setMessage('Hello ' + call.request.getName());
  return [null, reply]
}

Again, just ideas.

This feature would eliminate the need for wrapper code for users wanting to use this pattern. I would love to know if anyone is interested in this feature or planning on adding it. Thanks!

(moved from https://github.com/grpc/grpc/issues/12751)

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:185
  • Comments:39 (8 by maintainers)

github_iconTop GitHub Comments

84reactions
Jokerocommented, Jul 28, 2018

Promise is already must-have feature. For me callbacks are something from dawn of the dinosaurs 😃

46reactions
nahidakbarcommented, Apr 19, 2022

Still no official support for async/await/Promises? This is a serious issue. People have been trying to not write callbacks in node for the last 5 years. Makes applications hard to read and maintain. Adding noisy promisify boilerplate everywhere is also not ideal. That plain looks like you are using legacy deprecated tech.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Promises, async/await - The Modern JavaScript Tutorial
Promises, async/await · Introduction: callbacks · Promise · Promises chaining · Error handling with promises · Promise API · Promisification · Microtasks ·...
Read more >
Async Await in Node.js - How to Master it? - Blog - RisingStack
Async functions return a Promise by default, so you can rewrite any callback based function to use Promises, then await their resolution. You ......
Read more >
How to use Async & Await with promises in node.js - Medium
An async function is a modification to the syntax used in writing promises. You can call it syntactic sugar over promises. It only...
Read more >
Async and Await in JavaScript, the extension to a promise.
The keyword await is used to wait for a Promise. It can only be used inside an async function. This keyword makes JavaScript...
Read more >
Are you using promises and async / await safely in Node.js?
Your route handler functions can use async / await – The framework will explicitly wait for the promise wrapping the route handler function...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found