From cb9136d27fc267ab483a203b60a3df9bbdfa2217 Mon Sep 17 00:00:00 2001 From: Sebastian Schmidt Date: Sun, 29 Dec 2019 16:35:06 +0800 Subject: [PATCH] fix: wait for client before checking for terminate (#186) * fix: wait for client before checking for terminate * fix: baselines Co-authored-by: Alexander Fenster --- .../typescript_gapic/src/$version/$service_client.ts.njk | 8 ++++---- .../src/v1/key_management_service_client.ts.baseline | 8 ++++---- .../redis/src/v1beta1/cloud_redis_client.ts.baseline | 8 ++++---- .../testdata/showcase/src/v1beta1/echo_client.ts.baseline | 8 ++++---- .../texttospeech/src/v1/text_to_speech_client.ts.baseline | 8 ++++---- .../src/v3beta1/translation_service_client.ts.baseline | 8 ++++---- 6 files changed, 24 insertions(+), 24 deletions(-) diff --git a/templates/typescript_gapic/src/$version/$service_client.ts.njk b/templates/typescript_gapic/src/$version/$service_client.ts.njk index 7ab37d0e8..181af2921 100644 --- a/templates/typescript_gapic/src/$version/$service_client.ts.njk +++ b/templates/typescript_gapic/src/$version/$service_client.ts.njk @@ -245,6 +245,9 @@ export class {{ service.name }}Client { for (const methodName of {{ service.name.toCamelCase() }}StubMethods) { const innerCallPromise = this.{{ service.name.toCamelCase() }}Stub.then( stub => (...args: Array<{}>) => { + if (this._terminated) { + return Promise.reject('The client has already been closed.'); + } return stub[methodName].apply(stub, args); }, (err: Error|null|undefined) => () => { @@ -264,10 +267,7 @@ export class {{ service.name }}Client { callOptions?: CallOptions, callback?: APICallback ) => { - if (this._terminated) { - return Promise.reject('The client has already been closed.'); - } - return apiCall(argument, callOptions, callback); + return apiCall(argument, callOptions, callback); }; } } diff --git a/typescript/test/testdata/keymanager/src/v1/key_management_service_client.ts.baseline b/typescript/test/testdata/keymanager/src/v1/key_management_service_client.ts.baseline index 2e43f655b..defdb9a9b 100644 --- a/typescript/test/testdata/keymanager/src/v1/key_management_service_client.ts.baseline +++ b/typescript/test/testdata/keymanager/src/v1/key_management_service_client.ts.baseline @@ -177,6 +177,9 @@ export class KeyManagementServiceClient { for (const methodName of keyManagementServiceStubMethods) { const innerCallPromise = this.keyManagementServiceStub.then( stub => (...args: Array<{}>) => { + if (this._terminated) { + return Promise.reject('The client has already been closed.'); + } return stub[methodName].apply(stub, args); }, (err: Error|null|undefined) => () => { @@ -196,10 +199,7 @@ export class KeyManagementServiceClient { callOptions?: CallOptions, callback?: APICallback ) => { - if (this._terminated) { - return Promise.reject('The client has already been closed.'); - } - return apiCall(argument, callOptions, callback); + return apiCall(argument, callOptions, callback); }; } } diff --git a/typescript/test/testdata/redis/src/v1beta1/cloud_redis_client.ts.baseline b/typescript/test/testdata/redis/src/v1beta1/cloud_redis_client.ts.baseline index d76403b4b..987749e49 100644 --- a/typescript/test/testdata/redis/src/v1beta1/cloud_redis_client.ts.baseline +++ b/typescript/test/testdata/redis/src/v1beta1/cloud_redis_client.ts.baseline @@ -252,6 +252,9 @@ export class CloudRedisClient { for (const methodName of cloudRedisStubMethods) { const innerCallPromise = this.cloudRedisStub.then( stub => (...args: Array<{}>) => { + if (this._terminated) { + return Promise.reject('The client has already been closed.'); + } return stub[methodName].apply(stub, args); }, (err: Error|null|undefined) => () => { @@ -271,10 +274,7 @@ export class CloudRedisClient { callOptions?: CallOptions, callback?: APICallback ) => { - if (this._terminated) { - return Promise.reject('The client has already been closed.'); - } - return apiCall(argument, callOptions, callback); + return apiCall(argument, callOptions, callback); }; } } diff --git a/typescript/test/testdata/showcase/src/v1beta1/echo_client.ts.baseline b/typescript/test/testdata/showcase/src/v1beta1/echo_client.ts.baseline index d8367428b..e0e044abc 100644 --- a/typescript/test/testdata/showcase/src/v1beta1/echo_client.ts.baseline +++ b/typescript/test/testdata/showcase/src/v1beta1/echo_client.ts.baseline @@ -196,6 +196,9 @@ export class EchoClient { for (const methodName of echoStubMethods) { const innerCallPromise = this.echoStub.then( stub => (...args: Array<{}>) => { + if (this._terminated) { + return Promise.reject('The client has already been closed.'); + } return stub[methodName].apply(stub, args); }, (err: Error|null|undefined) => () => { @@ -215,10 +218,7 @@ export class EchoClient { callOptions?: CallOptions, callback?: APICallback ) => { - if (this._terminated) { - return Promise.reject('The client has already been closed.'); - } - return apiCall(argument, callOptions, callback); + return apiCall(argument, callOptions, callback); }; } } diff --git a/typescript/test/testdata/texttospeech/src/v1/text_to_speech_client.ts.baseline b/typescript/test/testdata/texttospeech/src/v1/text_to_speech_client.ts.baseline index 766e672fd..414e83565 100644 --- a/typescript/test/testdata/texttospeech/src/v1/text_to_speech_client.ts.baseline +++ b/typescript/test/testdata/texttospeech/src/v1/text_to_speech_client.ts.baseline @@ -152,6 +152,9 @@ export class TextToSpeechClient { for (const methodName of textToSpeechStubMethods) { const innerCallPromise = this.textToSpeechStub.then( stub => (...args: Array<{}>) => { + if (this._terminated) { + return Promise.reject('The client has already been closed.'); + } return stub[methodName].apply(stub, args); }, (err: Error|null|undefined) => () => { @@ -171,10 +174,7 @@ export class TextToSpeechClient { callOptions?: CallOptions, callback?: APICallback ) => { - if (this._terminated) { - return Promise.reject('The client has already been closed.'); - } - return apiCall(argument, callOptions, callback); + return apiCall(argument, callOptions, callback); }; } } diff --git a/typescript/test/testdata/translate/src/v3beta1/translation_service_client.ts.baseline b/typescript/test/testdata/translate/src/v3beta1/translation_service_client.ts.baseline index a6715bfa7..d143de4f1 100644 --- a/typescript/test/testdata/translate/src/v3beta1/translation_service_client.ts.baseline +++ b/typescript/test/testdata/translate/src/v3beta1/translation_service_client.ts.baseline @@ -214,6 +214,9 @@ export class TranslationServiceClient { for (const methodName of translationServiceStubMethods) { const innerCallPromise = this.translationServiceStub.then( stub => (...args: Array<{}>) => { + if (this._terminated) { + return Promise.reject('The client has already been closed.'); + } return stub[methodName].apply(stub, args); }, (err: Error|null|undefined) => () => { @@ -233,10 +236,7 @@ export class TranslationServiceClient { callOptions?: CallOptions, callback?: APICallback ) => { - if (this._terminated) { - return Promise.reject('The client has already been closed.'); - } - return apiCall(argument, callOptions, callback); + return apiCall(argument, callOptions, callback); }; } }