MCPcopy Index your code
hub / github.com/coder/coder / singleflightDoChan

Function singleflightDoChan

coderd/x/chatd/configcache.go:118–132  ·  view source on GitHub ↗

singleflightDoChan wraps a singleflight group's DoChan method, allowing the caller to abandon the wait if their context is canceled while the shared fill continues running to completion. This separates two lifetimes: the fill runs under the server-scoped context, while each caller waits under its ow

(
	ctx context.Context,
	group *singleflight.Group[K, V],
	key K,
	fn func() (V, error),
)

Source from the content-addressed store, hash-verified

116// This separates two lifetimes: the fill runs under the server-scoped
117// context, while each caller waits under its own request-scoped context.
118func singleflightDoChan[K comparable, V any](
119 ctx context.Context,
120 group *singleflight.Group[K, V],
121 key K,
122 fn func() (V, error),
123) (V, error) {
124 ch := group.DoChan(key, fn)
125 select {
126 case <-ctx.Done():
127 var zero V
128 return zero, ctx.Err()
129 case res := <-ch:
130 return res.Val, res.Err
131 }
132}
133
134func (c *chatConfigCache) EnabledProviders(ctx context.Context) ([]database.AIProvider, error) {
135 if providers, ok := c.cachedProviders(); ok {

Callers 5

EnabledProvidersMethod · 0.85
ModelConfigByIDMethod · 0.85
DefaultModelConfigMethod · 0.85
UserPromptMethod · 0.85
AdvisorConfigMethod · 0.85

Calls 2

ErrMethod · 0.80
DoneMethod · 0.45

Tested by

no test coverage detected