mirror of https://github.com/grpc/grpc-web.git
Add a ThenableCall base class for the promise-based unaryCall function
This commit is contained in:
parent
b89d8f122c
commit
6e632b4183
|
@ -97,6 +97,7 @@ AbstractClientBase.prototype.rpcCall = function(
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @abstract
|
* @abstract
|
||||||
|
* @protected
|
||||||
* @template REQUEST, RESPONSE
|
* @template REQUEST, RESPONSE
|
||||||
* @param {string} method The method to invoke
|
* @param {string} method The method to invoke
|
||||||
* @param {REQUEST} requestMessage The request proto
|
* @param {REQUEST} requestMessage The request proto
|
||||||
|
@ -104,10 +105,10 @@ AbstractClientBase.prototype.rpcCall = function(
|
||||||
* @param {!MethodDescriptor<REQUEST, RESPONSE>|
|
* @param {!MethodDescriptor<REQUEST, RESPONSE>|
|
||||||
* !AbstractClientBase.MethodInfo<REQUEST,RESPONSE>}
|
* !AbstractClientBase.MethodInfo<REQUEST,RESPONSE>}
|
||||||
* methodDescriptor Information of this RPC method
|
* methodDescriptor Information of this RPC method
|
||||||
* @return {!Promise<!RESPONSE>}
|
* @return {!IThenable <!RESPONSE>}
|
||||||
* A promise that resolves to the response message
|
* A promise that resolves to the response message
|
||||||
*/
|
*/
|
||||||
AbstractClientBase.prototype.unaryCall = function(
|
AbstractClientBase.prototype.thenableCall = function(
|
||||||
method, requestMessage, metadata, methodDescriptor) {};
|
method, requestMessage, metadata, methodDescriptor) {};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,7 @@ const ClientReadableStream = goog.require('grpc.web.ClientReadableStream');
|
||||||
const Error = goog.require('grpc.web.Error');
|
const Error = goog.require('grpc.web.Error');
|
||||||
const GrpcWebClientReadableStream = goog.require('grpc.web.GrpcWebClientReadableStream');
|
const GrpcWebClientReadableStream = goog.require('grpc.web.GrpcWebClientReadableStream');
|
||||||
const HttpCors = goog.require('goog.net.rpc.HttpCors');
|
const HttpCors = goog.require('goog.net.rpc.HttpCors');
|
||||||
|
const MethodDescriptor = goog.requireType('grpc.web.MethodDescriptor');
|
||||||
const MethodType = goog.require('grpc.web.MethodType');
|
const MethodType = goog.require('grpc.web.MethodType');
|
||||||
const Request = goog.require('grpc.web.Request');
|
const Request = goog.require('grpc.web.Request');
|
||||||
const StatusCode = goog.require('grpc.web.StatusCode');
|
const StatusCode = goog.require('grpc.web.StatusCode');
|
||||||
|
@ -112,7 +113,7 @@ GrpcWebClientBase.prototype.rpcCall = function(
|
||||||
* @override
|
* @override
|
||||||
* @export
|
* @export
|
||||||
*/
|
*/
|
||||||
GrpcWebClientBase.prototype.unaryCall = function(
|
GrpcWebClientBase.prototype.thenableCall = function(
|
||||||
method, requestMessage, metadata, methodDescriptor) {
|
method, requestMessage, metadata, methodDescriptor) {
|
||||||
methodDescriptor = AbstractClientBase.ensureMethodDescriptor(
|
methodDescriptor = AbstractClientBase.ensureMethodDescriptor(
|
||||||
method, requestMessage, MethodType.UNARY, methodDescriptor);
|
method, requestMessage, MethodType.UNARY, methodDescriptor);
|
||||||
|
@ -144,6 +145,23 @@ GrpcWebClientBase.prototype.unaryCall = function(
|
||||||
return unaryResponse.then((response) => response.getResponseMessage());
|
return unaryResponse.then((response) => response.getResponseMessage());
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @export
|
||||||
|
* @param {string} method The method to invoke
|
||||||
|
* @param {REQUEST} requestMessage The request proto
|
||||||
|
* @param {!Object<string, string>} metadata User defined call metadata
|
||||||
|
* @param {!MethodDescriptor<REQUEST, RESPONSE>|
|
||||||
|
* !AbstractClientBase.MethodInfo<REQUEST,RESPONSE>}
|
||||||
|
* methodDescriptor Information of this RPC method
|
||||||
|
* @return {!Promise<RESPONSE>}
|
||||||
|
* @template REQUEST, RESPONSE
|
||||||
|
*/
|
||||||
|
GrpcWebClientBase.prototype.unaryCall = function(
|
||||||
|
method, requestMessage, metadata, methodDescriptor) {
|
||||||
|
return /** @type {!Promise<RESPONSE>}*/ (
|
||||||
|
this.thenableCall(method, requestMessage, metadata, methodDescriptor));
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @override
|
* @override
|
||||||
|
|
Loading…
Reference in New Issue