MCPcopy
hub / github.com/panjf2000/ants / Submit

Method Submit

pool.go:37–47  ·  view source on GitHub ↗

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())

Source from the content-addressed store, hash-verified

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).
37func (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.
50func NewPool(size int, options ...Option) (*Pool, error) {

Callers 15

TestPanicHandlerFunction · 0.95
TestPurgePoolFunction · 0.95
TestPurgePreMallocPoolFunction · 0.95
TestNonblockingSubmitFunction · 0.95
TestMaxBlockingSubmitFunction · 0.95
TestRebootNewPoolFunction · 0.95

Calls 3

retrieveWorkerMethod · 0.80
inputFuncMethod · 0.65
IsClosedMethod · 0.45

Tested by 15

TestPanicHandlerFunction · 0.76
TestPurgePoolFunction · 0.76
TestPurgePreMallocPoolFunction · 0.76
TestNonblockingSubmitFunction · 0.76
TestMaxBlockingSubmitFunction · 0.76
TestRebootNewPoolFunction · 0.76