UNPKG

3.04 kBTypeScriptView Raw
1import { StatusObject } from './call-interface';
2import { Metadata } from './metadata';
3import { Status } from './constants';
4import { LoadBalancer } from './load-balancer';
5import { SubchannelInterface } from './subchannel-interface';
6export declare enum PickResultType {
7 COMPLETE = 0,
8 QUEUE = 1,
9 TRANSIENT_FAILURE = 2,
10 DROP = 3
11}
12export interface PickResult {
13 pickResultType: PickResultType;
14 /**
15 * The subchannel to use as the transport for the call. Only meaningful if
16 * `pickResultType` is COMPLETE. If null, indicates that the call should be
17 * dropped.
18 */
19 subchannel: SubchannelInterface | null;
20 /**
21 * The status object to end the call with. Populated if and only if
22 * `pickResultType` is TRANSIENT_FAILURE.
23 */
24 status: StatusObject | null;
25 onCallStarted: (() => void) | null;
26 onCallEnded: ((statusCode: Status) => void) | null;
27}
28export interface CompletePickResult extends PickResult {
29 pickResultType: PickResultType.COMPLETE;
30 subchannel: SubchannelInterface | null;
31 status: null;
32 onCallStarted: (() => void) | null;
33 onCallEnded: ((statusCode: Status) => void) | null;
34}
35export interface QueuePickResult extends PickResult {
36 pickResultType: PickResultType.QUEUE;
37 subchannel: null;
38 status: null;
39 onCallStarted: null;
40 onCallEnded: null;
41}
42export interface TransientFailurePickResult extends PickResult {
43 pickResultType: PickResultType.TRANSIENT_FAILURE;
44 subchannel: null;
45 status: StatusObject;
46 onCallStarted: null;
47 onCallEnded: null;
48}
49export interface DropCallPickResult extends PickResult {
50 pickResultType: PickResultType.DROP;
51 subchannel: null;
52 status: StatusObject;
53 onCallStarted: null;
54 onCallEnded: null;
55}
56export interface PickArgs {
57 metadata: Metadata;
58 extraPickInfo: {
59 [key: string]: string;
60 };
61}
62/**
63 * A proxy object representing the momentary state of a load balancer. Picks
64 * subchannels or returns other information based on that state. Should be
65 * replaced every time the load balancer changes state.
66 */
67export interface Picker {
68 pick(pickArgs: PickArgs): PickResult;
69}
70/**
71 * A standard picker representing a load balancer in the TRANSIENT_FAILURE
72 * state. Always responds to every pick request with an UNAVAILABLE status.
73 */
74export declare class UnavailablePicker implements Picker {
75 private status;
76 constructor(status?: StatusObject);
77 pick(pickArgs: PickArgs): TransientFailurePickResult;
78}
79/**
80 * A standard picker representing a load balancer in the IDLE or CONNECTING
81 * state. Always responds to every pick request with a QUEUE pick result
82 * indicating that the pick should be tried again with the next `Picker`. Also
83 * reports back to the load balancer that a connection should be established
84 * once any pick is attempted.
85 */
86export declare class QueuePicker {
87 private loadBalancer;
88 private calledExitIdle;
89 constructor(loadBalancer: LoadBalancer);
90 pick(pickArgs: PickArgs): QueuePickResult;
91}
92
\No newline at end of file