func NewConnection()

in client.go [593:618]


func NewConnection(ctx context.Context, channelID string, client *agentcommunication.Client) (*Connection, error) {
	conn := &Connection{
		channelID:           channelID,
		closed:              make(chan struct{}),
		messages:            make(chan *acpb.MessageBody),
		responseSubs:        make(map[string]chan *status.Status),
		streamReady:         make(chan struct{}),
		sends:               make(chan *acpb.StreamAgentMessagesRequest),
		timeToWaitForResp:   2 * time.Second,
		client:              client,
		callerManagedClient: true,
	}

	var err error
	conn.resourceID, err = getResourceID()
	if err != nil {
		return nil, err
	}

	if err := conn.createStream(ctx); err != nil {
		conn.close(err)
		return nil, err
	}

	return conn, nil
}