Skip to content

Instantly share code, notes, and snippets.

@stephenplusplus
Last active June 20, 2017 18:59
Show Gist options
  • Select an option

  • Save stephenplusplus/d95b525964495293c24830ed6452e5b9 to your computer and use it in GitHub Desktop.

Select an option

Save stephenplusplus/d95b525964495293c24830ed6452e5b9 to your computer and use it in GitHub Desktop.
grpc-request.js
var pumpify = require('pumpify')
var through = require('through2')
function makeGrpcStreamingRequest() {
var transformStream = through.obj(function(obj, enc, next) {
obj.transformed = true
next(null, obj)
})
var grpcRequestStream = through.obj()
return pumpify.obj(transformStream, grpcRequestStream)
}
var stream = makeGrpcStreamingRequest()
stream.on('data', console.log)
var request = {
configurationSetting: true,
anotherSetting: false
}
stream.write(request)
var anotherRequest = {
configurationSetting: false,
anotherSetting: true
}
stream.write(anotherRequest)
stream.end()
// Actual requests sent (output from `console.log`):
// {
// configurationSetting: true,
// anotherSetting: false,
// transformed: true
// }
//
// {
// configurationSetting: false,
// anotherSetting: true,
// transformed: true
// }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment