pull-grpc
v1.0.0
Published
GRPC pull stream interface
Downloads
2
Readme
pull-grpc
GRPC pull stream interface.
Usage
const pull = require('pull-stream')
const grpc = require('pull-grpc')
const uri = 'localhost:50051'
const schema = `
syntax = "proto3";
package messages;
service MessageThing {
rpc EchoHello (stream Sup) returns (stream Sup) {}
}
message Sup {
required string msg = 1;
}
`
// server: echo each request back as the response
const server = grpc.server(schema, {
echoHello: (call) => pull(call, call)
})
server.listen(uri, { secure: false })
// client: send the message "hey world" once
const sink = grpc.client(uri, { secure: false }, (err, source) => {
if (err) throw err
pull(source, pull.drain(write, end))
function write (data) {
console.log(`data: ${data}`)
// => "data: hey world"
}
function end (err) {
if (err) throw err
console.log('server done!')
server.close()
}
})
pull(pull.once({ msg: 'hey world' }), sink)
API
pullGrpc
Installation
$ npm install pull-grpc