| 16 | } |
| 17 | |
| 18 | func newAsyncQueue(length, maxConcurrency int) *asyncQueue { |
| 19 | q := &asyncQueue{ |
| 20 | stopCh: make(chan struct{}), |
| 21 | queueCh: make(chan func(), length), |
| 22 | } |
| 23 | // Start a number of goroutines - processing async operations - equal |
| 24 | // to the max concurrency we have. |
| 25 | q.workers.Add(maxConcurrency) |
| 26 | for i := 0; i < maxConcurrency; i++ { |
| 27 | go q.asyncQueueProcessLoop() |
| 28 | } |
| 29 | return q |
| 30 | } |
| 31 | |
| 32 | // submit adds an operation to the queue or returns an error if the queue is full |
| 33 | func (q *asyncQueue) submit(op func()) error { |