Skip to content

[NodeJS] Promises and async/await #12751

Closed

Description

@alexkreidler

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:

client.sayHello(request, function(err, response) {
console.log('Greeting:', response.getMessage());
});

We could write:

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

Or something similar. On the server side, instead of:

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

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!

Activity

  1. murgatroid99 commented on Sep 28, 2017

    @murgatroid99
    Member

    Would you mind opening this against https://github.com/grpc/grpc-node? Going forward, that's where gRPC Node development will be, so it would be better to have this discussion there.

  2. alexkreidler commented on Sep 29, 2017

    @alexkreidler
    Author
  3. locked as resolved and limited conversation to collaborators on Oct 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions