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), )
| 116 | // This separates two lifetimes: the fill runs under the server-scoped |
| 117 | // context, while each caller waits under its own request-scoped context. |
| 118 | func 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 | |
| 134 | func (c *chatConfigCache) EnabledProviders(ctx context.Context) ([]database.AIProvider, error) { |
| 135 | if providers, ok := c.cachedProviders(); ok { |
no test coverage detected