mirror of https://github.com/grpc/grpc-node.git
Merge pull request #841 from cjihrig/constant
grpc-js: don't export private symbol
This commit is contained in:
commit
309033f681
|
@ -24,9 +24,7 @@ import {ChannelOptions} from './channel-options';
|
|||
import {Status} from './constants';
|
||||
import {Metadata} from './metadata';
|
||||
|
||||
// This symbol must be exported (for now).
|
||||
// See: https://github.com/Microsoft/TypeScript/issues/20080
|
||||
export const kChannel = Symbol();
|
||||
const CHANNEL_SYMBOL = Symbol();
|
||||
|
||||
export interface UnaryCallback<ResponseType> {
|
||||
(err: ServiceError|null, value?: ResponseType): void;
|
||||
|
@ -52,26 +50,26 @@ export type ClientOptions = Partial<ChannelOptions>&{
|
|||
* clients.
|
||||
*/
|
||||
export class Client {
|
||||
private readonly[kChannel]: Channel;
|
||||
private readonly[CHANNEL_SYMBOL]: Channel;
|
||||
constructor(
|
||||
address: string, credentials: ChannelCredentials,
|
||||
options: ClientOptions = {}) {
|
||||
if (options.channelOverride) {
|
||||
this[kChannel] = options.channelOverride;
|
||||
this[CHANNEL_SYMBOL] = options.channelOverride;
|
||||
} else if (options.channelFactoryOverride) {
|
||||
this[kChannel] =
|
||||
this[CHANNEL_SYMBOL] =
|
||||
options.channelFactoryOverride(address, credentials, options);
|
||||
} else {
|
||||
this[kChannel] = new Http2Channel(address, credentials, options);
|
||||
this[CHANNEL_SYMBOL] = new Http2Channel(address, credentials, options);
|
||||
}
|
||||
}
|
||||
|
||||
close(): void {
|
||||
this[kChannel].close();
|
||||
this[CHANNEL_SYMBOL].close();
|
||||
}
|
||||
|
||||
getChannel(): Channel {
|
||||
return this[kChannel];
|
||||
return this[CHANNEL_SYMBOL];
|
||||
}
|
||||
|
||||
waitForReady(deadline: Deadline, callback: (error?: Error) => void): void {
|
||||
|
@ -82,7 +80,7 @@ export class Client {
|
|||
}
|
||||
let newState;
|
||||
try {
|
||||
newState = this[kChannel].getConnectivityState(true);
|
||||
newState = this[CHANNEL_SYMBOL].getConnectivityState(true);
|
||||
} catch (e) {
|
||||
callback(new Error('The channel has been closed'));
|
||||
return;
|
||||
|
@ -91,7 +89,8 @@ export class Client {
|
|||
callback();
|
||||
} else {
|
||||
try {
|
||||
this[kChannel].watchConnectivityState(newState, deadline, checkState);
|
||||
this[CHANNEL_SYMBOL].watchConnectivityState(
|
||||
newState, deadline, checkState);
|
||||
} catch (e) {
|
||||
callback(new Error('The channel has been closed'));
|
||||
}
|
||||
|
@ -188,7 +187,7 @@ export class Client {
|
|||
({metadata, options, callback} =
|
||||
this.checkOptionalUnaryResponseArguments<ResponseType>(
|
||||
metadata, options, callback));
|
||||
const call: Call = this[kChannel].createCall(
|
||||
const call: Call = this[CHANNEL_SYMBOL].createCall(
|
||||
method, options.deadline, options.host, null, options.propagate_flags);
|
||||
if (options.credentials) {
|
||||
call.setCredentials(options.credentials);
|
||||
|
@ -229,7 +228,7 @@ export class Client {
|
|||
({metadata, options, callback} =
|
||||
this.checkOptionalUnaryResponseArguments<ResponseType>(
|
||||
metadata, options, callback));
|
||||
const call: Call = this[kChannel].createCall(
|
||||
const call: Call = this[CHANNEL_SYMBOL].createCall(
|
||||
method, options.deadline, options.host, null, options.propagate_flags);
|
||||
if (options.credentials) {
|
||||
call.setCredentials(options.credentials);
|
||||
|
@ -277,7 +276,7 @@ export class Client {
|
|||
metadata?: Metadata|CallOptions,
|
||||
options?: CallOptions): ClientReadableStream<ResponseType> {
|
||||
({metadata, options} = this.checkMetadataAndOptions(metadata, options));
|
||||
const call: Call = this[kChannel].createCall(
|
||||
const call: Call = this[CHANNEL_SYMBOL].createCall(
|
||||
method, options.deadline, options.host, null, options.propagate_flags);
|
||||
if (options.credentials) {
|
||||
call.setCredentials(options.credentials);
|
||||
|
@ -304,7 +303,7 @@ export class Client {
|
|||
metadata?: Metadata|CallOptions,
|
||||
options?: CallOptions): ClientDuplexStream<RequestType, ResponseType> {
|
||||
({metadata, options} = this.checkMetadataAndOptions(metadata, options));
|
||||
const call: Call = this[kChannel].createCall(
|
||||
const call: Call = this[CHANNEL_SYMBOL].createCall(
|
||||
method, options.deadline, options.host, null, options.propagate_flags);
|
||||
if (options.credentials) {
|
||||
call.setCredentials(options.credentials);
|
||||
|
|
Loading…
Reference in New Issue