Queue queues a job to be run by a worker.
(job func(), timeout time.Duration)
| 58 | |
| 59 | // Queue queues a job to be run by a worker. |
| 60 | func (pool *WorkerPool) Queue(job func(), timeout time.Duration) bool { |
| 61 | if pool.stopped() { |
| 62 | return false |
| 63 | } |
| 64 | var t <-chan time.Time |
| 65 | if timeout > 0 { |
| 66 | t = time.After(timeout) |
| 67 | } |
| 68 | select { |
| 69 | case pool.jobs <- job: |
| 70 | case <-t: |
| 71 | return false |
| 72 | case <-pool.quit: |
| 73 | return false |
| 74 | } |
| 75 | return true |
| 76 | } |
| 77 | |
| 78 | // Stop stops the pool and waits for all workers to return. |
| 79 | func (pool *WorkerPool) Stop() { |