diff options
Diffstat (limited to 'src/node/interop/interop_server.js')
-rw-r--r-- | src/node/interop/interop_server.js | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/src/node/interop/interop_server.js b/src/node/interop/interop_server.js index 5321005c86..9526b5d183 100644 --- a/src/node/interop/interop_server.js +++ b/src/node/interop/interop_server.js @@ -36,6 +36,7 @@ var fs = require('fs'); var path = require('path'); var _ = require('lodash'); +var AsyncDelayQueue = require('./async_delay_queue'); var grpc = require('..'); var testProto = grpc.load({ root: __dirname + '/../../..', @@ -155,6 +156,7 @@ function handleStreamingInput(call, callback) { */ function handleStreamingOutput(call) { echoHeader(call); + var delay_queue = new AsyncDelayQueue(); var req = call.request; if (req.response_status) { var status = req.response_status; @@ -163,9 +165,15 @@ function handleStreamingOutput(call) { return; } _.each(req.response_parameters, function(resp_param) { - call.write({payload: getPayload(req.response_type, resp_param.size)}); + delay_queue.add(function(next) { + call.write({payload: getPayload(req.response_type, resp_param.size)}); + next(); + }, resp_param.interval_us); + }); + delay_queue.add(function(next) { + call.end(getEchoTrailer(call)); + next(); }); - call.end(getEchoTrailer(call)); } /** @@ -175,6 +183,7 @@ function handleStreamingOutput(call) { */ function handleFullDuplex(call) { echoHeader(call); + var delay_queue = new AsyncDelayQueue(); call.on('data', function(value) { if (value.response_status) { var status = value.response_status; @@ -183,11 +192,17 @@ function handleFullDuplex(call) { return; } _.each(value.response_parameters, function(resp_param) { - call.write({payload: getPayload(value.response_type, resp_param.size)}); + delay_queue.add(function(next) { + call.write({payload: getPayload(value.response_type, resp_param.size)}); + next(); + }, resp_param.interval_us); }); }); call.on('end', function() { - call.end(getEchoTrailer(call)); + delay_queue.add(function(next) { + call.end(getEchoTrailer(call)); + next(); + }); }); } |