MCPcopy Index your code
hub / github.com/flant/shell-operator / IterateSnapshot

Method IterateSnapshot

pkg/task/queue/queue_set.go:187–205  ·  view source on GitHub ↗

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))

Source from the content-addressed store, hash-verified

185//
186// Memory overhead: O(n) where n is the number of queues.
187func (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
207func (tqs *TaskQueueSet) Remove(name string) {
208 ts, exists := tqs.Queues.Get(name)

Callers 1

StartMethod · 0.95

Calls 1

GetSnapshotMethod · 0.95

Tested by

no test coverage detected