github.com/stackb/rules_proto@v0.0.0-20240221195024-5428336c51f1/example/routeguide/closure/client.js (about) 1 goog.module('example.routeguide.closure.GrpcJsClient'); 2 3 const Feature = goog.require('proto.example.routeguide.Feature'); 4 const GoogPromise = goog.require('goog.Promise'); 5 const Rectangle = goog.require('proto.example.routeguide.Rectangle'); 6 const RouteguideClient = goog.require('proto.example.routeguide.RouteguideClient'); 7 8 /** 9 * A skeleton client. The point of this exercise is not actually to create a 10 * routeguide client, but show how we can use protobufs in closure code. 11 */ 12 class GrpcJsClient { 13 constructor() { 14 /** 15 * @const @private @type {!RouteguideClient} 16 */ 17 this.client_ = new RouteguideClient(); 18 } 19 20 /** 21 * List existing features. Promise resolves to a list of features. 22 * 23 * @param {!Rectangle} rect 24 * @return {!GoogPromise<!Array<!Feature>>} feature 25 */ 26 listFeatures(rect) { 27 /** 28 * @type {!Array<!Feature>} 29 */ 30 const features = []; 31 32 return this.client_.getRouteGuide() 33 .listFeatures(rect, f => features.push(f)) 34 .then(() => features); 35 } 36 37 /** 38 * Run the client. A real implementation might actually do something here. 39 */ 40 run() { 41 console.log("Running grpc.js routeguide client..."); 42 } 43 } 44 exports = GrpcJsClient;