GetCount get the node count in query and only return zero when working zero
()
| 153 | |
| 154 | // GetCount get the node count in query and only return zero when working zero |
| 155 | func (q *Queue) GetCountWithWorkingBlock() int64 { |
| 156 | q.mux.Lock() |
| 157 | defer q.mux.Unlock() |
| 158 | |
| 159 | for { |
| 160 | if q.count == 0 && q.working > 0 { |
| 161 | q.mux.Unlock() |
| 162 | |
| 163 | time.Sleep(time.Second) |
| 164 | |
| 165 | q.mux.Lock() |
| 166 | } else { |
| 167 | return q.count |
| 168 | } |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | // NewQueue create and init a new Queue |
| 173 | func NewQueue() *Queue { |