diff options
author | murgatroid99 <michael.lumish@gmail.com> | 2015-01-28 11:47:23 -0800 |
---|---|---|
committer | murgatroid99 <michael.lumish@gmail.com> | 2015-01-28 11:47:23 -0800 |
commit | 684f6f4359a4c09b3430ae8da80f9db5ac00a603 (patch) | |
tree | 2523a4cc8eb0142606e84510227a7ac97c60e0c7 /src/node | |
parent | 7f791669df8a7728bc5aa3c52246a15d7aebe370 (diff) |
Added metadata pass-through to server method handlers
Diffstat (limited to 'src/node')
-rw-r--r-- | src/node/src/surface_server.js | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/src/node/src/surface_server.js b/src/node/src/surface_server.js index af23ec211c..cf342fc9fd 100644 --- a/src/node/src/surface_server.js +++ b/src/node/src/surface_server.js @@ -129,16 +129,18 @@ ServerWritableObjectStream.prototype._write = _write; /** * Creates a binary stream handler function from a unary handler function - * @param {function(Object, function(Error, *))} handler Unary call handler - * @return {function(stream)} Binary stream handler + * @param {function(Object, function(Error, *), metadata=)} handler Unary call + * handler + * @return {function(stream, metadata=)} Binary stream handler */ function makeUnaryHandler(handler) { /** * Handles a stream by reading a single data value, passing it to the handler, * and writing the response back to the stream. * @param {stream} stream Binary data stream + * @param {metadata=} metadata Incoming metadata array */ - return function handleUnaryCall(stream) { + return function handleUnaryCall(stream, metadata) { stream.on('data', function handleUnaryData(value) { var call = {request: value}; Object.defineProperty(call, 'cancelled', { @@ -154,7 +156,7 @@ function makeUnaryHandler(handler) { stream.write(value); stream.end(); } - }); + }, metadata); }); }; } @@ -162,17 +164,18 @@ function makeUnaryHandler(handler) { /** * Creates a binary stream handler function from a client stream handler * function - * @param {function(Readable, function(Error, *))} handler Client stream call - * handler - * @return {function(stream)} Binary stream handler + * @param {function(Readable, function(Error, *), metadata=)} handler Client + * stream call handler + * @return {function(stream, metadata=)} Binary stream handler */ function makeClientStreamHandler(handler) { /** * Handles a stream by passing a deserializing stream to the handler and * writing the response back to the stream. * @param {stream} stream Binary data stream + * @param {metadata=} metadata Incoming metadata array */ - return function handleClientStreamCall(stream) { + return function handleClientStreamCall(stream, metadata) { var object_stream = new ServerReadableObjectStream(stream); handler(object_stream, function sendClientStreamData(err, value) { if (err) { @@ -181,35 +184,36 @@ function makeClientStreamHandler(handler) { stream.write(value); stream.end(); } - }); + }, metadata); }; } /** * Creates a binary stream handler function from a server stream handler * function - * @param {function(Writable)} handler Server stream call handler - * @return {function(stream)} Binary stream handler + * @param {function(Writable, metadata=)} handler Server stream call handler + * @return {function(stream, metadata=)} Binary stream handler */ function makeServerStreamHandler(handler) { /** * Handles a stream by attaching it to a serializing stream, and passing it to * the handler. * @param {stream} stream Binary data stream + * @param {metadata=} metadata Incoming metadata array */ - return function handleServerStreamCall(stream) { + return function handleServerStreamCall(stream, metadata) { stream.on('data', function handleClientData(value) { var object_stream = new ServerWritableObjectStream(stream); object_stream.request = value; - handler(object_stream); + handler(object_stream, metadata); }); }; } /** * Creates a binary stream handler function from a bidi stream handler function - * @param {function(Duplex)} handler Unary call handler - * @return {function(stream)} Binary stream handler + * @param {function(Duplex, metadata=)} handler Unary call handler + * @return {function(stream, metadata=)} Binary stream handler */ function makeBidiStreamHandler(handler) { return handler; |