Skip to content
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

[Features] Node client support Promise #8592

Closed
leaves4j opened this issue Nov 1, 2016 · 4 comments
Closed

[Features] Node client support Promise #8592

leaves4j opened this issue Nov 1, 2016 · 4 comments

Comments

@leaves4j
Copy link

leaves4j commented Nov 1, 2016

Can we support client return a Promise?

client.sayHello({name: user})
.then(res => {
  console.log('Greeting:', res.message);
})
.catch(err => throw err);
@sulliwane
Copy link

sulliwane commented Nov 1, 2016

The Node API for GRPC is only callback based. But you can use promisifyAll() from bluebird library to create a promised based version of your grpc methods:

const bluebird = require('bluebird');
// Cb style
const clientCb = require('grpc').client;
clientCb({}, function cb(result) {});
// Promise style
const client = bluebird.promisifyAll(client);
client.sayHelloAsync({}).then((result) => {});

@leaves4j
Copy link
Author

leaves4j commented Nov 1, 2016

@sulliwane Thanks, I write a simple module that support both callback based and Promise, called grpc-promisify

@murgatroid99
Copy link
Member

I want to note that your grpc-promisify only works with single request/single response methods. With other types of methods, it will pass the wrong arguments and overwrite important information in the return value.

@leaves4j
Copy link
Author

leaves4j commented Nov 2, 2016

@murgatroid99 tks

@hsaliak hsaliak closed this as completed Nov 16, 2016
@lock lock bot locked as resolved and limited conversation to collaborators Oct 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants