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