grpc-client-promise-wrapper
v1.0.5
Published
Wrap the function of the grpc client, don't use callback anymore
Downloads
48
Maintainers
Readme
grpc-client-promise-wrapper
Documentation
Use async/await for @grpc/grpc-js package
Installation
$ npm install grpc-client-promise-wrapper
Javascript
const promiseWrapper = require('grpc-client-promise-wrapper');
Typescript
import * as promiseWrapper from 'grpc-client-promise-wrapper';
Example
- test.proto
syntax = "proto3";
package test;
service TestService {
rpc GetTestFn (inputParam) returns (returnValue);
}
message InputParam {
string inputParam = 1;
}
message ReturnValue {
string returnValue = 1;
}
- app.js
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);
};