Giter Site home page Giter Site logo

grpc-promise's People

Contributors

carlessistare avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

grpc-promise's Issues

Type Error crashes promisify.

With the most recent grpc update the library now crashes with the error

TypeError: requestTypes[originalFunction.name] is not a function

Timeout when executing client in bidirectional streaming example

In bidirectional example on client-side there is a call to .end() method which always results in a timeout. Happens when executing the client when there is a delay on server-side.
I recommend moving it to the callback of .sendMessage({})method after outputting the results:

 t = client.streamAction();
  t.sendMessage({})
    .then(res => {
      console.log('Client: Stream Message Received = ', res); // Client: Stream Message Received = {id: 1}
      t.end();
    })
    .catch(err => console.error(err));

Thanks for the great module.
Edit: Ending would also be required in .catch(), so I would suggest perhaps using async/await syntax to prevent DRY. The following simple example should work on client-side:

  try {
    t = client.streamAction();
    const res = await t.sendMessage({});
    console.log(res);
  }
  catch(err) { 
    console.log(err);
  }
  t.end();

Accessing original callback function

After promisifying all functions in the RPC, how do I access the original callback function, if I desire to use both promise and callback versions?

** Great library, by the way...

Streaming-Response RPCs should not wait for end of stream

Currently, a promisified streaming-response function returns a promise that resolves when the server ends the stream. One use-case of streaming-response RPCs is, however, that the client processes the reponse stream while the server is still executing the response. With the current implemenation, this is not possible, as the client receives the data in one go, when the stream completes.

This also makes it impossible to use infinite streams, as that causes the client to wait indefinitely.

Minimal example, JS client:

const grpc = require('grpc')
const grpcPromise = require('grpc-promise')
const protoLoader = require('@grpc/proto-loader')
const packageDefinition = protoLoader.loadSync(...)
const protoDescriptor = grpc.loadPackageDefinition(packageDefinition)
const client = new protoDescriptor.ExampleService('localhost:50051', grpc.credentials.createInsecure())
grpcPromise.promisifyAll(client)

client.exampleUnaryStream()
    .sendMessage({})
    .then(r => console.log(`RESPONSE ${JSON.stringify(r)}`))
    .catch(e => console.log(`ERROR ${JSON.stringify(e)}`))

Python Server (based on grpclib and betterproto, see this issue for details; this part is working and not the cause of the problem mentioned here):

class ExampleService(ServiceStub):
    service_name = "ExampleService"

    @rpc_unary_stream(name="ExampleUnaryStream")
    async def example_unary_stream(self, request: Empty) -> AsyncIterator[Empty]:
        for i in range(5):
            yield Empty()
            await asyncio.sleep(1)

server = Server([ExampleService()])
await server.start("localhost", 50051)
await server.wait_closed()

As a temporary work-around, I only promisify unary/unary functions:

const unaryFunctions = []
Object.keys(Object.getPrototypeOf(client)).forEach(functionName => {
    if (client[functionName].requestStream === false && client[functionName].responseStream === false) {
        unaryFunctions.push(functionName)
    }
})
grpcPromise.promisify(client, unaryFunctions)

I'm not quite sure how this could be done with promises but it would be nice to be able to register an onData callback somehow and still retain the nicer syntax that the promisified functions provide.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.