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