Hello , Can we get a better example for using gRPC streaming api without using sleep function in it ?
I would like the VU iteration to complete as soon the sever finishing the stream , Using Promise doesnt seem to work.
Referring to the example given in grpc-server-streaming.js
Hi @bandorko , I see the iteration terminates and cancels the stream if we remove the sleep. Would you be able to confirm this ?
I got some more time yesterday and had to return a promise to make it work which would resolve/reject based on the stream event handler callbacks. Also i had to switch to using default async function to be able to use the async/await pattern waiting for the stream results.
hi @bandorko , in my case since i abstract out all the stream calls into different method , my default main method look pretty simple and i have wait for stream end event to trigger before returning the final result.
It looks something like this
connected = false
client = null
export default async function (data) {
let input = "some random input";
let response = await grpc_streaming_call(input);
}
grpc_streaming_call(input) {
let output = []
if (!connected) {
client.connect(url,param)
}
return new Promise((resolve, reject) => {
const stream = new Stream(client, uri, params);
stream.on('data', (resp) => {
output.push(resp);
});
stream.on('error', (err) => {
console.log('Stream Error: ' + JSON.stringify(err));
reject(err)
});
stream.on('end', () => {
resolve(result);
});
stream.write(input);
stream.end();
});
}
This helps if i have to do additional calls based on the result from grpc response , @bandorko do you think this is the way to go or any other ways to do this better ?