Skip to content

Commit

Permalink
client now can listen for metadata and status without interceptors
Browse files Browse the repository at this point in the history
  • Loading branch information
Dnaganog committed Aug 10, 2019
1 parent 60edc01 commit 0421d95
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
8 changes: 5 additions & 3 deletions examples/firecomm/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ let certificate = path.join(__dirname, "/server.crt");

const stub = new firecomm.Stub(routeguide.RouteGuide, "localhost:3000");

const healthStub = new firecomm.HealthStub("localhost:3000");
// const healthStub = new firecomm.HealthStub("localhost:3000");

// healthStub
// .check()
Expand Down Expand Up @@ -70,12 +70,14 @@ const firstChat = {

// testClientStream();

const newClient = stub.clientStream({meta: 'data'}, [interceptorProvider])
const newClient = stub.clientStream()
.send({message: 'yolo'})
.send(firstChat)
.on((data) => console.log({ data }))
.on('status', (status) => console.log({ status }))
// .on('metadata', (metadata) => console.log({ metadata }))
.catch(err => console.log({ err }))
.retry()


setInterval(()=>{
newClient.send({message:'please'})
Expand Down
31 changes: 20 additions & 11 deletions lib/clientCalls/clientStreamCall.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ const generateMeta = require("../utils/generateMeta");
module.exports = function clientStreamCall(that, methodName, first, second) {
let metadata = null;
let interceptors = null;
let callback = function(err, res) {
if (err) clientStreamObj.$catch(err);
clientStreamObj.$on(res);
return clientStreamObj;
};
if (typeof first === "object") {
if (Array.isArray(first)) {
interceptors = { interceptors: first };
Expand All @@ -24,12 +19,17 @@ module.exports = function clientStreamCall(that, methodName, first, second) {
metadata = generateMeta(second);
}
}
let callback = function(err, res) {
if (err) clientStreamObj.$catch(err);
clientStreamObj.$on(res);
};
let sender = that[methodName](metadata, interceptors, callback);
const clientStreamObj = {
retry: function(metadata, interceptors) {
clientStreamObj.$on
sender = that[methodName](metadata, interceptors, callback);
return clientStreamObj;
// throw: function(metadata) {
// sender.throw()
// },
getPeer: function() {
return sender.getPeer();
},
send: function(message, flags, flushCallback) {
lastMessage = { message, flags, flushCallback };
Expand All @@ -48,7 +48,7 @@ module.exports = function clientStreamCall(that, methodName, first, second) {
clientStreamObj.$catch = first;
return clientStreamObj;
},
$on: () => {
$on: (res) => {
throw new Error(
"Client Stream: .catch and .on must be invoked to .send"
);
Expand All @@ -63,7 +63,16 @@ module.exports = function clientStreamCall(that, methodName, first, second) {
} else {
listenerCallback = second;
}
clientStreamObj.$on = listenerCallback;
switch (first) {
case 'status':
sender.on('status', second);
break;
case 'metadata':
sender.on('metadata', second);
break;
default:
clientStreamObj.$on = listenerCallback;
}
return clientStreamObj;
}
};
Expand Down
1 change: 0 additions & 1 deletion lib/custom-services/healthcheck-pkg.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@ const protoLoader = require("../build");
const PROTO_PATH = path.join(__dirname, "./healthcheck.proto");

const healthcheck = build(PROTO_PATH);
console.log(healthcheck._serviceName);
module.exports = healthcheck;

0 comments on commit 0421d95

Please sign in to comment.