I'm developing a Vue.js web application and I'm using gRPC to assure the communication.
In the frontend, I'm using the web version of gRPC: grpc-web
.
Everything is working just fine; however, when I'm doing an API call in my store, e.g.:
async fetchEcho() {
const echoService = new EchoServiceClient('http://localhost:8080', null, null);
const request = new EchoRequest();
request.setMessage('Hello World!');
const call = echoService.echo(request, {'custom-header-1': 'value1'},
(err: grpcWeb.Error, response: EchoResponse) => {
console.log(response.getMessage());
});
}
How can I use the async/await
pattern when making the call in my Vue file, e.g.:
await fetchEcho();
// ...
And await until the API call has finished to resume my the course of my program?
Thanks!
await
is used with promises. Is there a form ofecho
that returns a promise instead of calling a callback? – Ehudd