ReplaceProviders swaps the provider snapshot used by future Acquires. It is safe to call concurrently with Acquire and is a no-op after Shutdown.
(providers []aibridge.Provider)
| 119 | // It is safe to call concurrently with Acquire and is a no-op after |
| 120 | // Shutdown. |
| 121 | func (p *CachedBridgePool) ReplaceProviders(providers []aibridge.Provider) { |
| 122 | select { |
| 123 | case <-p.shuttingDownCh: |
| 124 | return |
| 125 | default: |
| 126 | } |
| 127 | snapshot := slices.Clone(providers) |
| 128 | p.providers.Store(&snapshot) |
| 129 | version := time.Now().UnixNano() |
| 130 | p.providerVersion.Store(version) |
| 131 | // Clear evicts every cached bridge; OnEvict shuts each one down in |
| 132 | // the background. Wait for buffered writes to drain so a replacement |
| 133 | // immediately followed by an Acquire always sees the cleared cache. |
| 134 | p.cache.Clear() |
| 135 | p.cache.Wait() |
| 136 | p.logger.Info(context.Background(), "request bridge pool reloaded", |
| 137 | slog.F("provider_count", len(snapshot)), |
| 138 | slog.F("provider_version", version), |
| 139 | ) |
| 140 | } |
| 141 | |
| 142 | // loadProviders returns the current providers snapshot. The returned |
| 143 | // slice must not be mutated. |