Skip to content
Snippets Groups Projects
Commit d3e95a36 authored by murgatroid99's avatar murgatroid99
Browse files

Added cancel to surface calls

parent 6cf933c4
No related branches found
No related tags found
No related merge requests found
...@@ -160,6 +160,14 @@ GrpcClientStream.prototype._write = function(chunk, encoding, callback) { ...@@ -160,6 +160,14 @@ GrpcClientStream.prototype._write = function(chunk, encoding, callback) {
}, 0); }, 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 * 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 * @param {grpc.Channel} channel The channel on which to make the request
......
...@@ -128,6 +128,16 @@ function _write(chunk, encoding, callback) { ...@@ -128,6 +128,16 @@ function _write(chunk, encoding, callback) {
*/ */
ClientWritableObjectStream.prototype._write = _write; 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. * Get a function that can make unary requests to the specified method.
* @param {string} method The name of the method to request * @param {string} method The name of the method to request
...@@ -155,6 +165,9 @@ function makeUnaryRequestFunction(method, serialize, deserialize) { ...@@ -155,6 +165,9 @@ function makeUnaryRequestFunction(method, serialize, deserialize) {
var stream = client.makeRequest(this.channel, method, serialize, var stream = client.makeRequest(this.channel, method, serialize,
deserialize, metadata, deadline); deserialize, metadata, deadline);
var emitter = new EventEmitter(); var emitter = new EventEmitter();
emitter.cancel = function cancel() {
stream.cancel();
};
forwardEvent(stream, emitter, 'status'); forwardEvent(stream, emitter, 'status');
forwardEvent(stream, emitter, 'metadata'); forwardEvent(stream, emitter, 'metadata');
stream.write(argument); stream.write(argument);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment