Submit submits a task to the pool. Note that you are allowed to call Pool.Submit() from the current Pool.Submit(), but what calls for special attention is that you will get blocked with the last Pool.Submit() call once the current Pool runs out of its capacity, and to avoid this, you should instant
(task func())
| 35 | // Pool.Submit() call once the current Pool runs out of its capacity, and to avoid this, |
| 36 | // you should instantiate a Pool with ants.WithNonblocking(true). |
| 37 | func (p *Pool) Submit(task func()) error { |
| 38 | if p.IsClosed() { |
| 39 | return ErrPoolClosed |
| 40 | } |
| 41 | |
| 42 | w, err := p.retrieveWorker() |
| 43 | if w != nil { |
| 44 | w.inputFunc(task) |
| 45 | } |
| 46 | return err |
| 47 | } |
| 48 | |
| 49 | // NewPool instantiates a Pool with customized options. |
| 50 | func NewPool(size int, options ...Option) (*Pool, error) { |