()
| 55 | } |
| 56 | |
| 57 | func (q *ListQueue) dispatcher() { |
| 58 | for { |
| 59 | q.lock.RLock() |
| 60 | if atomic.LoadUint32(&q.running) != 1 && q.list.Len() == 0 { |
| 61 | q.lock.RUnlock() |
| 62 | break |
| 63 | } |
| 64 | ele := q.list.Front() |
| 65 | q.lock.RUnlock() |
| 66 | |
| 67 | if ele == nil { |
| 68 | time.Sleep(time.Millisecond * 10) |
| 69 | continue |
| 70 | } |
| 71 | |
| 72 | worker := <-q.workerPool |
| 73 | worker <- ele.Value.(Jober) |
| 74 | |
| 75 | q.lock.Lock() |
| 76 | q.list.Remove(ele) |
| 77 | q.lock.Unlock() |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | // Push put the executable task into the queue |
| 82 | func (q *ListQueue) Push(job Jober) { |