MCPcopy
hub / github.com/grpc/grpc-go / chainStreamClientInterceptors

Function chainStreamClientInterceptors

clientconn.go:551–569  ·  view source on GitHub ↗

chainStreamClientInterceptors chains all stream client interceptors into one.

(cc *ClientConn)

Source from the content-addressed store, hash-verified

549
550// chainStreamClientInterceptors chains all stream client interceptors into one.
551func chainStreamClientInterceptors(cc *ClientConn) {
552 interceptors := cc.dopts.chainStreamInts
553 // Prepend dopts.streamInt to the chaining interceptors if it exists, since streamInt will
554 // be executed before any other chained interceptors.
555 if cc.dopts.streamInt != nil {
556 interceptors = append([]StreamClientInterceptor{cc.dopts.streamInt}, interceptors...)
557 }
558 var chainedInt StreamClientInterceptor
559 if len(interceptors) == 0 {
560 chainedInt = nil
561 } else if len(interceptors) == 1 {
562 chainedInt = interceptors[0]
563 } else {
564 chainedInt = func(ctx context.Context, desc *StreamDesc, cc *ClientConn, method string, streamer Streamer, opts ...CallOption) (ClientStream, error) {
565 return interceptors[0](ctx, desc, cc, method, getChainStreamer(interceptors, 0, streamer), opts...)
566 }
567 }
568 cc.dopts.streamInt = chainedInt
569}
570
571// getChainStreamer recursively generate the chained client stream constructor.
572func getChainStreamer(interceptors []StreamClientInterceptor, curr int, finalStreamer Streamer) Streamer {

Callers 1

NewClientFunction · 0.85

Calls 1

getChainStreamerFunction · 0.85

Tested by

no test coverage detected