Skip to content

Commit

Permalink
grpc-js: Use helper isFunction
Browse files Browse the repository at this point in the history
  • Loading branch information
zereraz committed Apr 24, 2021
1 parent 076aecc commit 7a8cd5a
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions packages/grpc-js/src/client.ts
Expand Up @@ -55,6 +55,10 @@ const INTERCEPTOR_SYMBOL = Symbol();
const INTERCEPTOR_PROVIDER_SYMBOL = Symbol();
const CALL_INVOCATION_TRANSFORMER_SYMBOL = Symbol();

function isFunction<ResponseType>(arg: Metadata | CallOptions | UnaryCallback<ResponseType>): boolean {
return Object.prototype.toString.call(arg) === '[object Function]'
}

export interface UnaryCallback<ResponseType> {
(err: ServiceError | null, value?: ResponseType): void;
}
Expand Down Expand Up @@ -198,9 +202,9 @@ export class Client {
options: CallOptions;
callback: UnaryCallback<ResponseType>;
} {
if (Object.prototype.toString.call(arg1) === '[object Function]') {
if (isFunction(arg1)) {
return { metadata: new Metadata(), options: {}, callback: arg1 };
} else if (Object.prototype.toString.call(arg2) === '[object Function]') {
} else if (isFunction(arg2)) {
if (arg1 instanceof Metadata) {
return { metadata: arg1, options: {}, callback: arg2 };
} else {
Expand All @@ -211,7 +215,7 @@ export class Client {
!(
arg1 instanceof Metadata &&
arg2 instanceof Object &&
Object.prototype.toString.call(arg3) === '[object Function]'
isFunction(arg3)
)
) {
throw new Error('Incorrect arguments passed');
Expand Down Expand Up @@ -671,3 +675,4 @@ export class Client {
return stream;
}
}

0 comments on commit 7a8cd5a

Please sign in to comment.