From d3e95a36327c7a2249434e554846c8e44aa7daa0 Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Mon, 26 Jan 2015 12:57:10 -0800 Subject: [PATCH] Added cancel to surface calls --- src/node/client.js | 8 ++++++++ src/node/surface_client.js | 13 +++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/node/client.js b/src/node/client.js index 7007852b939..a039b0dcfa6 100644 --- a/src/node/client.js +++ b/src/node/client.js @@ -160,6 +160,14 @@ GrpcClientStream.prototype._write = function(chunk, encoding, callback) { }, 0); }; +/** + * Cancel the ongoing call. If the call has not already finished, it will finish + * with status CANCELLED. + */ +GrpcClientStream.prototype.cancel = function() { + self._call.cancel(); +}; + /** * Make a request on the channel to the given method with the given arguments * @param {grpc.Channel} channel The channel on which to make the request diff --git a/src/node/surface_client.js b/src/node/surface_client.js index b63ae13e8dc..f7123450c2b 100644 --- a/src/node/surface_client.js +++ b/src/node/surface_client.js @@ -128,6 +128,16 @@ function _write(chunk, encoding, callback) { */ ClientWritableObjectStream.prototype._write = _write; +/** + * Cancel the underlying call + */ +function cancel() { + this._stream.cancel(); +} + +ClientReadableObjectStream.prototype.cancel = cancel; +ClientWritableObjectStream.prototype.cancel = cancel; + /** * Get a function that can make unary requests to the specified method. * @param {string} method The name of the method to request @@ -155,6 +165,9 @@ function makeUnaryRequestFunction(method, serialize, deserialize) { var stream = client.makeRequest(this.channel, method, serialize, deserialize, metadata, deadline); var emitter = new EventEmitter(); + emitter.cancel = function cancel() { + stream.cancel(); + }; forwardEvent(stream, emitter, 'status'); forwardEvent(stream, emitter, 'metadata'); stream.write(argument);