mirror of
https://github.com/coder/coder.git
synced 2026-09-22 05:05:20 +08:00
Adds client context to `Client()` method in `aibridged.Server`, effectivly renaming `ClientContext()` method as `Client()`. Similarly `aibridged.ClientFuncWithContext` became `aibridged.ClientFunc`. `aibridged.Server.Client()` acquired a DRPC client with `context.Background()`, callers in theory could wait indefinitely for the daemon to connect to coderd. Every call site already had a context except the recorder callback. `aibridge.NewRecorder` takes a `func(context.Context) (Recorder, error)` and acquires against the record call's context.
40 lines
937 B
Go
40 lines
937 B
Go
package aibridged
|
|
|
|
import (
|
|
"context"
|
|
|
|
"storj.io/drpc"
|
|
|
|
"github.com/coder/coder/v2/coderd/aibridged/proto"
|
|
)
|
|
|
|
type Dialer func(ctx context.Context) (DRPCClient, error)
|
|
|
|
// ClientFunc acquires a DRPCClient, honoring the passed context so a blocking
|
|
// acquisition (e.g. waiting for the daemon to connect to coderd) unblocks when
|
|
// the context is canceled. Server.Client satisfies it.
|
|
type ClientFunc func(context.Context) (DRPCClient, error)
|
|
|
|
// DRPCClient is the union of various service interfaces the client must support.
|
|
type DRPCClient interface {
|
|
proto.DRPCRecorderClient
|
|
proto.DRPCMCPConfiguratorClient
|
|
proto.DRPCAuthorizerClient
|
|
proto.DRPCProviderConfiguratorClient
|
|
}
|
|
|
|
var _ DRPCClient = &Client{}
|
|
|
|
type Client struct {
|
|
proto.DRPCRecorderClient
|
|
proto.DRPCMCPConfiguratorClient
|
|
proto.DRPCAuthorizerClient
|
|
proto.DRPCProviderConfiguratorClient
|
|
|
|
Conn drpc.Conn
|
|
}
|
|
|
|
func (c *Client) DRPCConn() drpc.Conn {
|
|
return c.Conn
|
|
}
|