Skip to content

Commit f98cda6

Browse files
committed
Run gts fix
1 parent 9916076 commit f98cda6

File tree

3 files changed

+103
-147
lines changed

3 files changed

+103
-147
lines changed

grpc-gcp/src/channel_ref.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,8 @@ export class ChannelRef {
3535
* @param activeStreamsCount Initial streams count.
3636
*/
3737
constructor(
38-
channel: grpc.ChannelInterface,
39-
channelId: number,
40-
affinityCount?: number,
41-
activeStreamsCount?: number
42-
) {
38+
channel: grpc.ChannelInterface, channelId: number, affinityCount?: number,
39+
activeStreamsCount?: number) {
4340
this.channel = channel;
4441
this.channelId = channelId;
4542
this.affinityCount = affinityCount ? affinityCount : 0;

grpc-gcp/src/gcp_channel_factory.ts

Lines changed: 31 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*/
1818

1919
import * as grpcType from '@grpc/grpc-js';
20-
import { ChannelInterface } from '@grpc/grpc-js';
20+
import {ChannelInterface} from '@grpc/grpc-js';
2121
import {promisify} from 'util';
2222

2323
import {ChannelRef} from './channel_ref';
@@ -38,15 +38,13 @@ export interface GcpChannelFactoryInterface extends grpcType.ChannelInterface {
3838
}
3939

4040
export interface GcpChannelFactoryConstructor {
41-
new (
42-
address: string,
43-
credentials: grpcType.ChannelCredentials,
44-
options: any
45-
): GcpChannelFactoryInterface;
41+
new(address: string, credentials: grpcType.ChannelCredentials,
42+
// tslint:disable-next-line:no-any options can be any object
43+
options: any): GcpChannelFactoryInterface;
4644
}
4745

48-
export default function(grpc: GrpcModule): GcpChannelFactoryConstructor {
49-
46+
export function getGcpChannelFactoryClass(grpc: GrpcModule):
47+
GcpChannelFactoryConstructor {
5048
/**
5149
* A channel management factory that implements grpc.Channel APIs.
5250
*/
@@ -66,18 +64,15 @@ export default function(grpc: GrpcModule): GcpChannelFactoryConstructor {
6664
* @param options A map of channel options.
6765
*/
6866
constructor(
69-
address: string,
70-
credentials: grpcType.ChannelCredentials,
71-
// tslint:disable-next-line:no-any options can be any object
72-
options: any
73-
) {
67+
address: string, credentials: grpcType.ChannelCredentials,
68+
// tslint:disable-next-line:no-any options can be any object
69+
options: any) {
7470
if (!options) {
7571
options = {};
7672
}
7773
if (typeof options !== 'object') {
7874
throw new TypeError(
79-
'Channel options must be an object with string keys and integer or string values'
80-
);
75+
'Channel options must be an object with string keys and integer or string values');
8176
}
8277
this.maxSize = 10;
8378
this.maxConcurrentStreamsLowWatermark = 100;
@@ -88,7 +83,7 @@ export default function(grpc: GrpcModule): GcpChannelFactoryConstructor {
8883
if (channelPool.maxSize) this.maxSize = channelPool.maxSize;
8984
if (channelPool.maxConcurrentStreamsLowWatermark) {
9085
this.maxConcurrentStreamsLowWatermark =
91-
channelPool.maxConcurrentStreamsLowWatermark;
86+
channelPool.maxConcurrentStreamsLowWatermark;
9287
}
9388
}
9489
this.initMethodToAffinityMap(gcpApiConfig);
@@ -138,23 +133,19 @@ export default function(grpc: GrpcModule): GcpChannelFactoryConstructor {
138133

139134
const size = this.channelRefs.length;
140135
// Chose the channelRef that has the least busy channel.
141-
if (
142-
size > 0 &&
143-
this.channelRefs[0].getActiveStreamsCount() <
144-
this.maxConcurrentStreamsLowWatermark
145-
) {
136+
if (size > 0 &&
137+
this.channelRefs[0].getActiveStreamsCount() <
138+
this.maxConcurrentStreamsLowWatermark) {
146139
return this.channelRefs[0];
147140
}
148141

149142
// If all existing channels are busy, and channel pool still has capacity,
150143
// create a new channel in the pool.
151144
if (size < this.maxSize) {
152-
const channelOptions = Object.assign({[CLIENT_CHANNEL_ID]: size}, this.options);
153-
const grpcChannel = new grpc.Channel(
154-
this.target,
155-
this.credentials,
156-
channelOptions
157-
);
145+
const channelOptions =
146+
Object.assign({[CLIENT_CHANNEL_ID]: size}, this.options);
147+
const grpcChannel =
148+
new grpc.Channel(this.target, this.credentials, channelOptions);
158149
const channelRef = new ChannelRef(grpcChannel, size);
159150
this.channelRefs.push(channelRef);
160151
return channelRef;
@@ -264,26 +255,24 @@ export default function(grpc: GrpcModule): GcpChannelFactoryConstructor {
264255
}
265256

266257
throw new Error(
267-
'Cannot get connectivity state because no channel provides valid state.'
268-
);
258+
'Cannot get connectivity state because no channel provides valid state.');
269259
}
270260

271261
/**
272262
* Watch for connectivity state changes.
273263
* @param currentState The state to watch for transitions from. This should
274-
* always be populated by calling getConnectivityState immediately before.
264+
* always be populated by calling getConnectivityState immediately
265+
* before.
275266
* @param deadline A deadline for waiting for a state change
276267
* @param callback Called with no error when the state changes, or with an
277268
* error if the deadline passes without a state change
278269
*/
279270
watchConnectivityState(
280-
currentState: grpcType.connectivityState,
281-
deadline: grpcType.Deadline,
282-
callback: (error?: Error) => void
283-
): void {
271+
currentState: grpcType.connectivityState, deadline: grpcType.Deadline,
272+
callback: (error?: Error) => void): void {
284273
if (!this.channelRefs.length) {
285274
callback(new Error(
286-
'Cannot watch connectivity state because there are no channels.'));
275+
'Cannot watch connectivity state because there are no channels.'));
287276
return;
288277
}
289278

@@ -294,12 +283,12 @@ export default function(grpc: GrpcModule): GcpChannelFactoryConstructor {
294283
return;
295284
}
296285

297-
const watchState = async (channelRef: ChannelRef): Promise<void> => {
286+
const watchState = async(channelRef: ChannelRef): Promise<void> => {
298287
const channel = channelRef.getChannel();
299288
const startingState = channel.getConnectivityState(false);
300289

301290
await promisify(channel.watchConnectivityState)
302-
.call(channel, startingState, deadline);
291+
.call(channel, startingState, deadline);
303292

304293
const state = this.getConnectivityState(false);
305294

@@ -326,20 +315,12 @@ export default function(grpc: GrpcModule): GcpChannelFactoryConstructor {
326315
* @return a grpc call object.
327316
*/
328317
createCall(
329-
method: string,
330-
deadline: grpcType.Deadline,
331-
host: string | null,
332-
parentCall: any,
333-
propagateFlags: number | null
334-
) {
318+
method: string, deadline: grpcType.Deadline, host: string|null,
319+
// tslint:disable-next-line:no-any There isn't a good type to use here
320+
parentCall: any, propagateFlags: number|null) {
335321
const grpcChannel = this.getChannelRef().getChannel();
336322
return grpcChannel.createCall(
337-
method,
338-
deadline,
339-
host,
340-
parentCall,
341-
propagateFlags
342-
);
323+
method, deadline, host, parentCall, propagateFlags);
343324
}
344-
}
325+
};
345326
}

0 commit comments

Comments
 (0)