Cancel closes the Queue and drains the pending commands without processing them, allowing for a fast "stop immediately"-ish operation.
()
| 165 | // Cancel closes the Queue and drains the pending commands without processing |
| 166 | // them, allowing for a fast "stop immediately"-ish operation. |
| 167 | func (q *Queue) Cancel() error { |
| 168 | select { |
| 169 | case <-q.cancelled: |
| 170 | // already cancelled, no-op |
| 171 | return nil |
| 172 | default: |
| 173 | // mark the queue as cancelled |
| 174 | close(q.cancelled) |
| 175 | // Close the Queue, that will wait for pending commands to drain |
| 176 | // will unblock any callers waiting on q.Block |
| 177 | return q.Close() |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | // Send enqueues a Command into the Fetcher. If the Queue has been closed, it |
| 182 | // returns ErrQueueClosed. The Command's URL must have a Host. |