carlessistare/grpc-promise

Timeout when executing client in bidirectional streaming example

Opened this issue · 0 comments

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();