Wrap the function of the grpc client, don't use callback anymore
Use async/await for @grpc/grpc-js package
$ npm install grpc-client-promise-wrapper
const promiseWrapper = require('grpc-client-promise-wrapper');
import * as promiseWrapper from 'grpc-client-promise-wrapper';
syntax = "proto3";
package test;
service TestService {
rpc GetTestFn (inputParam) returns (returnValue);
}
message InputParam {
string inputParam = 1;
}
message ReturnValue {
string returnValue = 1;
}
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');
const promiseWrapper = require('grpc-client-promise-wrapper');
const testStub = () => {
const packageDefinition = protoLoader.loadSync(path.join(__dirname, './test.proto'));
const testService = grpc.loadPackageDefinition(packageDefinition).test;
return promiseWrapper(new testService.TestService('localhost:3001', grpc.credentials.createInsecure()));
};
const getTestFn = async (params) => {
return testStub().getTestFn(params);
};