Skip to content

Commit

Permalink
update timing for client stream, server stream, bidi stream
Browse files Browse the repository at this point in the history
  • Loading branch information
danst3in committed Jan 30, 2020
1 parent 84e5158 commit 4390456
Showing 1 changed file with 39 additions and 8 deletions.
47 changes: 39 additions & 8 deletions src/client/controllers/grpcController.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ grpcController.openGrpcConnection = (reqResObj, connectionArray) => {
reqResObj.connection = 'closed';
reqResObj.connectionType = 'plain';
reqResObj.response.events.push(data)
reqResObj.response.events.push()
store.default.dispatch(actions.reqResUpdate(reqResObj));

})
Expand All @@ -236,12 +235,19 @@ grpcController.openGrpcConnection = (reqResObj, connectionArray) => {
return;
}
else {
//Close Connection for client Stream
reqResObj.connection = 'closed';
reqResObj.connectionType = 'plain';
reqResObj.timeReceived = Date.now();
reqResObj.response.events.push(response)
store.default.dispatch(actions.reqResUpdate(reqResObj));

console.log('in client stream response', response);
}});

// debugging call methods
console.log('call: ', call);

// let callStack = reqResObj.queryArr;
// console.log('callstack before map', callStack);
// callStack = callStack.map((ele)=> {
Expand All @@ -261,19 +267,18 @@ grpcController.openGrpcConnection = (reqResObj, connectionArray) => {
// console.log('callstack array', callStack)
for (var i = 0; i < queryArr.length; i++) {
let query = queryArr[i];
//Open Connection for client Stream
reqResObj.connection = 'open';
reqResObj.connectionType = 'plain';
reqResObj.timeSent = Date.now();
call.write(query);
// add console log for completed write?
}
call.end();
//Close Connection for client Stream
reqResObj.connection = 'closed';
reqResObj.connectionType = 'plain';
reqResObj.timeReceived = Date.now();
reqResObj.response.events.push(response)
store.default.dispatch(actions.reqResUpdate(reqResObj));


// reqResObj.response.events.push(response)
// store.default.dispatch(actions.reqResUpdate(reqResObj));
// add console log for completed call

// async.series(callStack, function(err, result) {
Expand All @@ -287,6 +292,10 @@ grpcController.openGrpcConnection = (reqResObj, connectionArray) => {
}
else if (rpcType === 'SERVER STREAM') {
let dataArr;
//Open Connection for SERVER Stream
reqResObj.connection = 'open';
reqResObj.connectionType = 'plain';
reqResObj.timeSent = Date.now();
const call = client[rpc](reqResObj.queryArr[0]);
call.on("data", resp => {
// console.log('server streaming message:', data);
Expand All @@ -305,16 +314,27 @@ grpcController.openGrpcConnection = (reqResObj, connectionArray) => {
console.log('server side stream erring out')
})
call.on('end', () => {
//Close Connection for SERVER Stream
reqResObj.connection = 'closed';
reqResObj.connectionType = 'plain';
reqResObj.timeReceived = Date.now();
// reqResObj.response.events.push(response) // no event expected from on 'end';
store.default.dispatch(actions.reqResUpdate(reqResObj));
// store.default.dispatch(actions.reqResUpdate(reqResObj));

console.log('server side stream completed')
})
}
//else BIDIRECTIONAL
else {

let call = client[rpc]();
call.on('data', (response) => {
// console.log('Got server response "' + response );
//Close Individual Connection for BIDIRECTIONAL Stream
reqResObj.connection = 'pending';
reqResObj.connectionType = 'plain';
reqResObj.timeReceived = Date.now();
reqResObj.response.events.push(response)
console.log(reqResObj.response.events)
store.default.dispatch(actions.reqResUpdate(reqResObj));
Expand All @@ -325,12 +345,23 @@ grpcController.openGrpcConnection = (reqResObj, connectionArray) => {
console.log('server ended connection with error')
})
call.on('end', (data)=> {
//Close Final Server Connection for BIDIRECTIONAL Stream
reqResObj.connection = 'closed';
reqResObj.connectionType = 'plain';
reqResObj.timeReceived = Date.now();
console.log('server response ended', data)
});

for (var i = 0; i < queryArr.length; i++) {
let query = queryArr[i];

//Open Connection for BIDIRECTIONAL Stream
if (i === 0){
reqResObj.connection = 'open';
} else {
reqResObj.connection = 'pending';
}
reqResObj.connectionType = 'plain';
reqResObj.timeSent = Date.now();
call.write(query);
}
call.end();
Expand Down

0 comments on commit 4390456

Please sign in to comment.