func newChannelContext(
	ctx context.Context,
	featureFlags FeatureFlags,
	options ...func(builder *contextBuilder),
) (context.Context, context.CancelFunc, []yarpc.CallOption) {
	return newChannelContextHelper(ctx, false, featureFlags, options...)
}
newChannelContext - Get a rpc channel context
package internal
import (
	"context"
	"encoding/json"
	"fmt"
	"os"
	"os/signal"
	"strings"
	"syscall"
	"time"
	"github.com/pborman/uuid"
	"github.com/uber-go/tally"
	s "go.uber.org/cadence/.gen/go/shared"
	"go.uber.org/cadence/internal/common"
	"go.uber.org/cadence/internal/common/metrics"
	"go.uber.org/yarpc"
)
const (
	libraryVersionHeaderName = "cadence-client-library-version"
	featureVersionHeaderName = "cadence-client-feature-version"
	clientImplHeaderName  = "cadence-client-name"
	clientImplHeaderValue = "uber-go"
	clientFeatureFlagsHeaderName = "cadence-client-feature-flags"
	defaultRPCTimeout = 10 * time.Second
	minRPCTimeout = 1 * time.Second
	maxRPCTimeout = 5 * time.Second
	maxQueryRPCTimeout = 20 * time.Second
)
type (
	FeatureFlags struct {
		WorkflowExecutionAlreadyCompletedErrorEnabled bool
	}
)
var (
	_yarpcCallOptions = []yarpc.CallOption{
		yarpc.WithHeader(libraryVersionHeaderName, LibraryVersion),
		yarpc.WithHeader(featureVersionHeaderName, FeatureVersion),
		yarpc.WithHeader(clientImplHeaderName, clientImplHeaderValue),
	}
)
func fromInternalFeatureFlags(featureFlags FeatureFlags) s.FeatureFlags {
	return s.FeatureFlags{
		WorkflowExecutionAlreadyCompletedErrorEnabled: common.BoolPtr(featureFlags.WorkflowExecutionAlreadyCompletedErrorEnabled),
	}
}
func toInternalFeatureFlags(featureFlags *s.FeatureFlags) FeatureFlags {
	flags := FeatureFlags{}
	if featureFlags != nil {
		if featureFlags.WorkflowExecutionAlreadyCompletedErrorEnabled != nil {
			flags.WorkflowExecutionAlreadyCompletedErrorEnabled = *featureFlags.WorkflowExecutionAlreadyCompletedErrorEnabled
		}
	}
	return flags
}
func featureFlagsHeader(featureFlags FeatureFlags) string {
	serialized := ""
	buf, err := json.Marshal(fromInternalFeatureFlags(featureFlags))
	if err == nil {
		serialized = string(buf)
	}
	return serialized
}
func getYarpcCallOptions(featureFlags FeatureFlags) []yarpc.CallOption {
	return append(
		_yarpcCallOptions,
		yarpc.WithHeader(clientFeatureFlagsHeaderName, featureFlagsHeader(featureFlags)),
	)
}
type contextBuilder struct {
	Timeout time.Duration
	ParentContext context.Context
}
func (cb *contextBuilder) Build() (context.Context, context.CancelFunc) {
	parent := cb.ParentContext
	if parent == nil {
		parent = context.Background()
	}
	return context.WithTimeout(parent, cb.Timeout)
}
func chanTimeout(timeout time.Duration) func(builder *contextBuilder) {
	return func(b *contextBuilder) {
		b.Timeout = timeout
	}
}
func newChannelContextForQuery(
	ctx context.Context,
	featureFlags FeatureFlags,
	options ...func(builder *contextBuilder),
) (context.Context, context.CancelFunc, []yarpc.CallOption) {
	return newChannelContextHelper(ctx, true, featureFlags, options...)
}