()
| 68 | } |
| 69 | |
| 70 | func (q *Queue) PullWithWorkingBlock() QueueNode { |
| 71 | q.mux.Lock() |
| 72 | defer q.mux.Unlock() |
| 73 | |
| 74 | for { |
| 75 | node := q.PullWithOutLock() |
| 76 | if node != nil { |
| 77 | q.working++ |
| 78 | |
| 79 | return node |
| 80 | } else if q.working > 0 { |
| 81 | q.mux.Unlock() |
| 82 | |
| 83 | time.Sleep(time.Second) |
| 84 | |
| 85 | q.mux.Lock() |
| 86 | } else { |
| 87 | return nil |
| 88 | } |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | // PushWithoutLock is no lock mode of Push |
| 93 | func (q *Queue) PushWithoutLock(node QueueNode) { |