(item T)
| 21 | } |
| 22 | |
| 23 | func (wq *WorkQueue[T]) Enqueue(item T) bool { |
| 24 | wq.lock.Lock() |
| 25 | defer wq.lock.Unlock() |
| 26 | if wq.closed { |
| 27 | return false |
| 28 | } |
| 29 | if !wq.started { |
| 30 | wq.started = true |
| 31 | wq.wg.Add(1) |
| 32 | go wq.worker() |
| 33 | } |
| 34 | wq.queue = append(wq.queue, item) |
| 35 | wq.cond.Signal() |
| 36 | return true |
| 37 | } |
| 38 | |
| 39 | func (wq *WorkQueue[T]) worker() { |
| 40 | defer wq.wg.Done() |