(n int)
| 57 | } |
| 58 | |
| 59 | func (pm *processorManager) concurrency(n int) { |
| 60 | pm.cancelsMu.Lock() |
| 61 | defer pm.cancelsMu.Unlock() |
| 62 | |
| 63 | if n < 0 { |
| 64 | n = 0 |
| 65 | } |
| 66 | |
| 67 | for len(pm.cancels) < n { |
| 68 | ctx, cancel := context.WithCancel(pm.ctx) |
| 69 | pm.cancels = append(pm.cancels, cancel) |
| 70 | |
| 71 | pm.wg.Go(func() { |
| 72 | |
| 73 | pm.currentProcessors.Inc() |
| 74 | defer pm.currentProcessors.Dec() |
| 75 | |
| 76 | pm.p.processQueriesOnSingleStream(ctx, pm.conn, pm.address) |
| 77 | }) |
| 78 | } |
| 79 | |
| 80 | for len(pm.cancels) > n { |
| 81 | pm.cancels[0]() |
| 82 | pm.cancels = pm.cancels[1:] |
| 83 | } |
| 84 | } |