-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
37 lines (29 loc) · 907 Bytes
/
index.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
const grpc = require('@grpc/grpc-js')
const protoLoader = require('@grpc/proto-loader')
const { createPrompt, cowsay } = require('./lib')
const PROTO_PATH = __dirname + '/.protop/path/protop/pingpong/api.proto'
protoLoader.load(PROTO_PATH)
.then(packageDefinition => {
const protos = grpc.loadPackageDefinition(packageDefinition)
const pingPongClient = new protos.protop.pingpong.PingPongService(
'localhost:8080',
grpc.credentials.createInsecure()
)
const exchange = pingPongClient.exchange()
const { openPrompt, closePrompt } = createPrompt({
'ping': () => exchange.write({/* Ping */})
})
exchange.on('data', data => {
cowsay('pong')
openPrompt()
})
exchange.on('end', () => {
closePrompt()
process.exit(0)
})
process.on('SIGINT', () => {
closePrompt()
exchange.end()
})
openPrompt()
})