UNPKG

3.75 kBTypeScriptView Raw
1import { ChannelCredentials } from './channel-credentials';
2import { ChannelOptions } from './channel-options';
3import { ServerSurfaceCall } from './server-call';
4import { ConnectivityState } from './connectivity-state';
5import { ChannelRef } from './channelz';
6import { Call } from './call-interface';
7import { Deadline } from './deadline';
8/**
9 * An interface that represents a communication channel to a server specified
10 * by a given address.
11 */
12export interface Channel {
13 /**
14 * Close the channel. This has the same functionality as the existing
15 * grpc.Client.prototype.close
16 */
17 close(): void;
18 /**
19 * Return the target that this channel connects to
20 */
21 getTarget(): string;
22 /**
23 * Get the channel's current connectivity state. This method is here mainly
24 * because it is in the existing internal Channel class, and there isn't
25 * another good place to put it.
26 * @param tryToConnect If true, the channel will start connecting if it is
27 * idle. Otherwise, idle channels will only start connecting when a
28 * call starts.
29 */
30 getConnectivityState(tryToConnect: boolean): ConnectivityState;
31 /**
32 * Watch for connectivity state changes. This is also here mainly because
33 * it is in the existing external Channel class.
34 * @param currentState The state to watch for transitions from. This should
35 * always be populated by calling getConnectivityState immediately
36 * before.
37 * @param deadline A deadline for waiting for a state change
38 * @param callback Called with no error when a state change, or with an
39 * error if the deadline passes without a state change.
40 */
41 watchConnectivityState(currentState: ConnectivityState, deadline: Date | number, callback: (error?: Error) => void): void;
42 /**
43 * Get the channelz reference object for this channel. A request to the
44 * channelz service for the id in this object will provide information
45 * about this channel.
46 */
47 getChannelzRef(): ChannelRef;
48 /**
49 * Create a call object. Call is an opaque type that is used by the Client
50 * class. This function is called by the gRPC library when starting a
51 * request. Implementers should return an instance of Call that is returned
52 * from calling createCall on an instance of the provided Channel class.
53 * @param method The full method string to request.
54 * @param deadline The call deadline
55 * @param host A host string override for making the request
56 * @param parentCall A server call to propagate some information from
57 * @param propagateFlags A bitwise combination of elements of grpc.propagate
58 * that indicates what information to propagate from parentCall.
59 */
60 createCall(method: string, deadline: Deadline, host: string | null | undefined, parentCall: ServerSurfaceCall | null, propagateFlags: number | null | undefined): Call;
61}
62export declare class ChannelImplementation implements Channel {
63 private internalChannel;
64 constructor(target: string, credentials: ChannelCredentials, options: ChannelOptions);
65 close(): void;
66 getTarget(): string;
67 getConnectivityState(tryToConnect: boolean): ConnectivityState;
68 watchConnectivityState(currentState: ConnectivityState, deadline: Date | number, callback: (error?: Error) => void): void;
69 /**
70 * Get the channelz reference object for this channel. The returned value is
71 * garbage if channelz is disabled for this channel.
72 * @returns
73 */
74 getChannelzRef(): ChannelRef;
75 createCall(method: string, deadline: Deadline, host: string | null | undefined, parentCall: ServerSurfaceCall | null, propagateFlags: number | null | undefined): Call;
76}