Skip to content
This repository was archived by the owner on Nov 18, 2025. It is now read-only.

Commit 816bf9b

Browse files
feat!: stop accepting Promise constructor (#737)
BREAKING CHANGE It won't be possible to pass a third-party Promise constructor (e.g. bluebird promise) to gax-managed client libraries.
1 parent d6e36c5 commit 816bf9b

15 files changed

Lines changed: 23 additions & 186 deletions

File tree

src/apiCaller.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,12 @@ import {GoogleError} from './googleError';
2828
import {NormalApiCaller} from './normalCalls/normalApiCaller';
2929
import {StreamProxy} from './streamingCalls/streaming';
3030

31-
export interface ApiCallerSettings {
32-
promise: PromiseConstructor;
33-
}
34-
3531
/**
3632
* An interface for all kinds of API callers (normal, that just calls API, and
3733
* all special ones: long-running, paginated, bundled, streaming).
3834
*/
3935
export interface APICaller {
40-
init(
41-
settings: ApiCallerSettings,
42-
callback?: APICallback
43-
): OngoingCallPromise | OngoingCall | StreamProxy;
36+
init(callback?: APICallback): OngoingCallPromise | OngoingCall | StreamProxy;
4437
wrap(func: GRPCCall): GRPCCall;
4538
call(
4639
apiCall: SimpleCallbackFunction,

src/bundlingCalls/bundleApiCaller.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
import {APICaller, ApiCallerSettings} from '../apiCaller';
17+
import {APICaller} from '../apiCaller';
1818
import {APICallback, GRPCCall, SimpleCallbackFunction} from '../apitypes';
1919
import {OngoingCall, OngoingCallPromise} from '../call';
2020
import {CallSettings} from '../gax';
@@ -34,14 +34,11 @@ export class BundleApiCaller implements APICaller {
3434
this.bundler = bundler;
3535
}
3636

37-
init(
38-
settings: ApiCallerSettings,
39-
callback?: APICallback
40-
): OngoingCallPromise | OngoingCall {
37+
init(callback?: APICallback): OngoingCallPromise | OngoingCall {
4138
if (callback) {
4239
return new OngoingCall(callback);
4340
}
44-
return new OngoingCallPromise(settings.promise);
41+
return new OngoingCallPromise();
4542
}
4643

4744
wrap(func: GRPCCall): GRPCCall {

src/call.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,11 @@ export class OngoingCallPromise extends OngoingCall {
9696
/**
9797
* GaxPromise is GRPCCallbackWrapper, but it holds a promise when
9898
* the API call finishes.
99-
* @param {Function} PromiseCtor - A constructor for a promise that implements
100-
* the ES6 specification of promise.
10199
* @constructor
102100
* @private
103101
*/
104102
// tslint:disable-next-line variable-name
105-
constructor(PromiseCtor: PromiseConstructor) {
103+
constructor() {
106104
let resolveCallback: (
107105
result: [ResponseType, NextPageRequestType, RawResponseType]
108106
) => void;
@@ -121,7 +119,7 @@ export class OngoingCallPromise extends OngoingCall {
121119
throw new GoogleError('Neither error nor response are defined');
122120
}
123121
};
124-
const promise = new PromiseCtor((resolve, reject) => {
122+
const promise = new Promise((resolve, reject) => {
125123
resolveCallback = resolve;
126124
rejectCallback = reject;
127125
}) as CancellablePromise<ResultTuple>;

src/createApiCall.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export function createApiCall(
7878
currentApiCaller = createAPICaller(settings, undefined);
7979
}
8080

81-
const ongoingCall = currentApiCaller.init(thisSettings, callback);
81+
const ongoingCall = currentApiCaller.init(callback);
8282
funcPromise
8383
.then((func: GRPCCall) => {
8484
// Initially, the function is just what gRPC server stub contains.

src/fallback.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ interface FallbackServiceStub {
6464
export class GrpcClient {
6565
auth?: OAuth2Client | GoogleAuth;
6666
authClient?: OAuth2Client | Compute | JWT | UserRefreshClient;
67-
promise?: PromiseConstructor;
6867
fallback: boolean;
6968
grpcVersion: string;
7069

@@ -74,8 +73,6 @@ export class GrpcClient {
7473
*
7574
* @param {Object=} options.auth - An instance of OAuth2Client to use in browser, or an instance of GoogleAuth from google-auth-library
7675
* to use in Node.js. Required for browser, optional for Node.js.
77-
* @param {Function=} options.promise - A constructor for a promise that
78-
* implements the ES6 specification of promise.
7976
* @constructor
8077
*/
8178

@@ -93,7 +90,6 @@ export class GrpcClient {
9390
(options.auth as GoogleAuth) ||
9491
new GoogleAuth(options as GoogleAuthOptions);
9592
}
96-
this.promise = 'promise' in options ? options.promise! : Promise;
9793
this.fallback = true;
9894
this.grpcVersion = 'fallback'; // won't be used anywhere but we need it to exist in the class
9995
}
@@ -202,8 +198,7 @@ export class GrpcClient {
202198
clientConfig,
203199
configOverrides,
204200
Status,
205-
{metadataBuilder: buildMetadata},
206-
this.promise
201+
{metadataBuilder: buildMetadata}
207202
);
208203
}
209204

@@ -374,8 +369,6 @@ export class GrpcClient {
374369
* gRPC-fallback version of lro
375370
*
376371
* @param {Object=} options.auth - An instance of google-auth-library.
377-
* @param {Function=} options.promise - A constructor for a promise that
378-
* implements the ES6 specification of promise.
379372
* @return {Object} A OperationsClientBuilder that will return a OperationsClient
380373
*/
381374
export function lro(options: GrpcClientOptions) {

src/gax.ts

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,6 @@ import {BundleOptions} from './bundlingCalls/bundleExecutor';
4848
* @property {boolean=} isBundling - If set to false and the call is configured
4949
* for bundling, bundling is not performed.
5050
* @property {BackoffSettings=} longrunning - BackoffSettings used for polling.
51-
* @property {Function=} promise - A constructor for a promise that implements the ES6
52-
* specification of promise which will be used to create promises. If not
53-
* provided, native promises will be used.
5451
* @example
5552
* // suppress bundling for bundled method.
5653
* api.bundlingMethod(
@@ -127,7 +124,6 @@ export interface CallOptions {
127124
bundleOptions?: BundleOptions | null;
128125
isBundling?: boolean;
129126
longrunning?: BackoffSettings;
130-
promise?: PromiseConstructor;
131127
}
132128

133129
export class CallSettings {
@@ -142,7 +138,6 @@ export class CallSettings {
142138
bundleOptions?: BundleOptions | null;
143139
isBundling: boolean;
144140
longrunning?: BackoffSettings;
145-
promise: PromiseConstructor;
146141

147142
/**
148143
* @param {Object} settings - An object containing parameters of this settings.
@@ -159,9 +154,6 @@ export class CallSettings {
159154
* in the page streaming request.
160155
* @param {Object} settings.otherArgs - Additional arguments to be passed to
161156
* the API calls.
162-
* @param {Function=} settings.promise - A constructor for a promise that
163-
* implements the ES6 specification of promise. If not provided, native
164-
* promises will be used.
165157
*
166158
* @constructor
167159
*/
@@ -178,7 +170,6 @@ export class CallSettings {
178170
this.isBundling = 'isBundling' in settings ? settings.isBundling! : true;
179171
this.longrunning =
180172
'longrunning' in settings ? settings.longrunning : undefined;
181-
this.promise = 'promise' in settings ? settings.promise! : Promise;
182173
}
183174

184175
/**
@@ -202,7 +193,6 @@ export class CallSettings {
202193
let otherArgs = this.otherArgs;
203194
let isBundling = this.isBundling;
204195
let longrunning = this.longrunning;
205-
let promise = this.promise;
206196
if ('timeout' in options) {
207197
timeout = options.timeout!;
208198
}
@@ -252,10 +242,6 @@ export class CallSettings {
252242
longrunning = options.longrunning;
253243
}
254244

255-
if ('promise' in options) {
256-
promise = options.promise!;
257-
}
258-
259245
return new CallSettings({
260246
timeout,
261247
retry,
@@ -267,7 +253,6 @@ export class CallSettings {
267253
maxResults,
268254
otherArgs,
269255
isBundling,
270-
promise,
271256
});
272257
}
273258
}
@@ -613,8 +598,6 @@ export interface ClientConfig {
613598
* those codes.
614599
* @param {Object} otherArgs - the non-request arguments to be passed to the API
615600
* calls.
616-
* @param {Function=} promise - A constructor for a promise that implements the
617-
* ES6 specification of promise. If not provided, native promises will be used.
618601
* @return {Object} A mapping from method name to CallSettings, or null if the
619602
* service is not found in the config.
620603
*/
@@ -623,8 +606,7 @@ export function constructSettings(
623606
clientConfig: ClientConfig,
624607
configOverrides: ClientConfig,
625608
retryNames: {},
626-
otherArgs?: {},
627-
promise?: PromiseConstructor
609+
otherArgs?: {}
628610
) {
629611
otherArgs = otherArgs || {};
630612
// tslint:disable-next-line no-any
@@ -679,7 +661,6 @@ export function constructSettings(
679661
? createBundleOptions(bundlingConfig)
680662
: null,
681663
otherArgs,
682-
promise: promise || Promise,
683664
});
684665
}
685666

src/grpc.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ const COMMON_PROTO_FILES = walk
4242

4343
export interface GrpcClientOptions extends GoogleAuthOptions {
4444
auth?: GoogleAuth;
45-
promise?: PromiseConstructor;
4645
grpc?: GrpcModule;
4746
}
4847

@@ -76,7 +75,6 @@ export class ClientStub extends grpc.Client {
7675

7776
export class GrpcClient {
7877
auth: GoogleAuth;
79-
promise: PromiseConstructor;
8078
grpc: GrpcModule;
8179
grpcVersion: string;
8280
fallback: boolean;
@@ -93,14 +91,10 @@ export class GrpcClient {
9391
* @param {Object=} options.grpc - When specified, this will be used
9492
* for the 'grpc' module in this context. By default, it will load the grpc
9593
* module in the standard way.
96-
* @param {Function=} options.promise - A constructor for a promise that
97-
* implements the ES6 specification of promise. If not provided, native
98-
* promises will be used.
9994
* @constructor
10095
*/
10196
constructor(options: GrpcClientOptions = {}) {
10297
this.auth = options.auth || new GoogleAuth(options);
103-
this.promise = options.promise || Promise;
10498
this.fallback = false;
10599

106100
if ('grpc' in options) {
@@ -258,8 +252,7 @@ export class GrpcClient {
258252
clientConfig,
259253
configOverrides,
260254
this.grpc.status,
261-
{metadataBuilder: this.metadataBuilder(headers)},
262-
this.promise
255+
{metadataBuilder: this.metadataBuilder(headers)}
263256
);
264257
}
265258

src/longRunningCalls/longRunningApiCaller.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
import {APICaller, ApiCallerSettings} from '../apiCaller';
17+
import {APICaller} from '../apiCaller';
1818
import {APICallback, GRPCCall, SimpleCallbackFunction} from '../apitypes';
1919
import {OngoingCall, OngoingCallPromise} from '../call';
2020
import {
@@ -45,14 +45,11 @@ export class LongrunningApiCaller implements APICaller {
4545
this.longrunningDescriptor = longrunningDescriptor;
4646
}
4747

48-
init(
49-
settings: ApiCallerSettings,
50-
callback?: APICallback
51-
): OngoingCallPromise | OngoingCall {
48+
init(callback?: APICallback): OngoingCallPromise | OngoingCall {
5249
if (callback) {
5350
return new OngoingCall(callback);
5451
}
55-
return new OngoingCallPromise(settings.promise);
52+
return new OngoingCallPromise();
5653
}
5754

5855
wrap(func: GRPCCall): GRPCCall {

src/longRunningCalls/longrunning.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,7 @@ export class Operation extends EventEmitter {
163163
function promisifyResponse() {
164164
if (!callback) {
165165
// tslint:disable-next-line variable-name
166-
const PromiseCtor = self._callOptions!.promise!;
167-
return new PromiseCtor((resolve, reject) => {
166+
return new Promise((resolve, reject) => {
168167
if (self.latestResponse.error) {
169168
const error = new GoogleError(self.latestResponse.error.message!);
170169
error.code = self.latestResponse.error.code!;
@@ -339,8 +338,7 @@ export class Operation extends EventEmitter {
339338
*/
340339
promise() {
341340
// tslint:disable-next-line variable-name
342-
const PromiseCtor = this._callOptions!.promise!;
343-
return new PromiseCtor((resolve, reject) => {
341+
return new Promise((resolve, reject) => {
344342
this.on('error', reject).on(
345343
'complete',
346344
(result, metadata, rawResponse) => {

src/normalCalls/normalApiCaller.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
import {APICaller, ApiCallerSettings} from '../apiCaller';
17+
import {APICaller} from '../apiCaller';
1818
import {APICallback, GRPCCall, SimpleCallbackFunction} from '../apitypes';
1919
import {OngoingCall, OngoingCallPromise} from '../call';
2020
import {GoogleError} from '../googleError';
@@ -23,14 +23,11 @@ import {GoogleError} from '../googleError';
2323
* Creates an API caller for regular unary methods.
2424
*/
2525
export class NormalApiCaller implements APICaller {
26-
init(
27-
settings: ApiCallerSettings,
28-
callback?: APICallback
29-
): OngoingCallPromise | OngoingCall {
26+
init(callback?: APICallback): OngoingCallPromise | OngoingCall {
3027
if (callback) {
3128
return new OngoingCall(callback);
3229
}
33-
return new OngoingCallPromise(settings.promise);
30+
return new OngoingCallPromise();
3431
}
3532

3633
wrap(func: GRPCCall): GRPCCall {

0 commit comments

Comments
 (0)