@@ -8,6 +8,7 @@ import { ClientOptions } from '../interfaces/client-metadata.interface';
88import { GRPC_DEFAULT_URL } from './../constants' ;
99import { ClientGrpc , GrpcOptions } from './../interfaces' ;
1010import { ClientProxy } from './client-proxy' ;
11+ import { GRPC_CANCELLED } from './constants' ;
1112
1213let grpcPackage : any = { } ;
1314
@@ -25,7 +26,7 @@ export class ClientGrpcProxy extends ClientProxy implements ClientGrpc {
2526 this . grpcClient = this . createClient ( ) ;
2627 }
2728
28- public getService < T extends { } > ( name : keyof T ) : T {
29+ public getService < T extends { } > ( name : string ) : T {
2930 const { options } = this . options as GrpcOptions ;
3031 if ( ! this . grpcClient [ name ] ) {
3132 throw new InvalidGrpcServiceException ( ) ;
@@ -59,14 +60,15 @@ export class ClientGrpcProxy extends ClientProxy implements ClientGrpc {
5960 ) : ( ...args ) => Observable < any > {
6061 return ( ...args ) => {
6162 return new Observable ( observer => {
62- const call = client [ methodName ] ( ...args ) ;
6363 let isClientCanceled = false ;
64+ const call = client [ methodName ] ( ...args ) ;
65+
6466 call . on ( 'data' , ( data : any ) => observer . next ( data ) ) ;
6567 call . on ( 'error' , ( error : any ) => {
66- if ( error . details === 'Cancelled' ) {
68+ if ( error . details === GRPC_CANCELLED ) {
6769 call . destroy ( ) ;
68- if ( isClientCanceled ) {
69- return ; // do not error if cancel was inititiated by Client
70+ if ( isClientCanceled ) {
71+ return ;
7072 }
7173 }
7274 observer . error ( error ) ;
@@ -76,10 +78,11 @@ export class ClientGrpcProxy extends ClientProxy implements ClientGrpc {
7678 observer . complete ( ) ;
7779 } ) ;
7880 return ( ) => {
79- if ( ! call . finished ) {
80- isClientCanceled = true ;
81- call . cancel ( ) ;
81+ if ( call . finished ) {
82+ return undefined ;
8283 }
84+ isClientCanceled = true ;
85+ call . cancel ( ) ;
8386 } ;
8487 } ) ;
8588 } ;
0 commit comments