IterateSnapshot creates a snapshot of all queues and iterates over the copy. This is safer than Iterate() when you need to call queue methods inside the callback, as no locks are held during callback execution. Note: The snapshot may become stale during iteration if queues are added/removed by othe
(ctx context.Context, doFn func(ctx context.Context, queue *TaskQueue))
| 185 | // |
| 186 | // Memory overhead: O(n) where n is the number of queues. |
| 187 | func (tqs *TaskQueueSet) IterateSnapshot(ctx context.Context, doFn func(ctx context.Context, queue *TaskQueue)) { |
| 188 | if doFn == nil { |
| 189 | return |
| 190 | } |
| 191 | |
| 192 | // Create snapshot under lock (main queue is already first) |
| 193 | snapshot := tqs.GetSnapshot() |
| 194 | |
| 195 | // Execute callbacks without holding any locks |
| 196 | defer func() { |
| 197 | if r := recover(); r != nil { |
| 198 | tqs.logger.Warn("panic recovered in IterateSnapshot", slog.Any(pkg.LogKeyError, r)) |
| 199 | } |
| 200 | }() |
| 201 | |
| 202 | for _, q := range snapshot { |
| 203 | doFn(ctx, q) |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | func (tqs *TaskQueueSet) Remove(name string) { |
| 208 | ts, exists := tqs.Queues.Get(name) |