Class: Channel

grpc. Channel


new Channel(target, credentials, options)

This constructor API is almost identical to the Client constructor, except that some of the options for the Client constructor are not valid here.

Parameters:
Name Type Description
target string

The address of the server to connect to

credentials grpc.ChannelCredentials

Channel credentials to use when connecting

options grpc~ChannelOptions

A map of channel options that will be passed to the core

Methods


close()

Close the channel. This has the same functionality as the existing grpc.Client#close


createCall(method, deadline, host, parentCall, propagateFlags)

Create a call object. Call is an opaque type used by the grpc.Client and grpc.Server classes. This function is called by the gRPC library when starting a request. Implementers should return an instance of Call that is returned from calling createCall on an instance of the provided Channel class.

Parameters:
Name Type Description
method string

The full method string to request

deadline grpc~Deadline

The call deadline

host string | null

A host string override for making the request

parentCall grpc~Call | null

A server call to propagate some information from

propagateFlags number | null

A bitwise combination of elements of grpc.propagate that indicates what information to propagate from parentCall

Returns:
Type
grpc~Call

getConnectivityState(tryToConnect)

Get the channel's current connectivity state.

Parameters:
Name Type Description
tryToConnect boolean

If true, the channel will start connecting if it is idle. Otherwise, idle channels will only start connecting when a call starts.

Returns:

The current connectivity state

Type
grpc.connectivityState

getTarget()

Return the target that this channel connects to

Returns:

The target

Type
string

watchConnectivityState(currentState, deadline, callback)

Watch for connectivity state changes.

Parameters:
Name Type Description
currentState grpc.ConnectivityState

The state to watch for transitions from. This should always be populated by calling getConnectivityState immediately before.

deadline grpc~Deadline

A deadline for waiting for a state change

callback grpc.Channel~watchConnectivityStateCallback

Called with no error when the state changes, or with an error if the deadline passes without a state change

Type Definitions


watchConnectivityStateCallback(error)

Parameters:
Name Type Argument Description
error Error <nullable>