Close closes the Queue so that no more Commands can be sent. It blocks until the Fetcher drains all pending commands. After the call, the Fetcher is stopped. Attempts to enqueue new URLs after Close has been called will always result in a ErrQueueClosed error.
()
| 132 | // Attempts to enqueue new URLs after Close has been called will always result in |
| 133 | // a ErrQueueClosed error. |
| 134 | func (q *Queue) Close() error { |
| 135 | // Make sure it is not already closed, as this is a run-time panic |
| 136 | select { |
| 137 | case <-q.closed: |
| 138 | // Already closed, no-op |
| 139 | return nil |
| 140 | default: |
| 141 | // Close the signal-channel |
| 142 | close(q.closed) |
| 143 | // Send a nil Command to make sure the processQueue method sees the close signal. |
| 144 | q.ch <- nil |
| 145 | // Wait for the Fetcher to drain. |
| 146 | q.wg.Wait() |
| 147 | // Unblock any callers waiting on q.Block |
| 148 | close(q.done) |
| 149 | return nil |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | // Block blocks the current goroutine until the Queue is closed and all pending |
| 154 | // commands are drained. |
no outgoing calls