File tree Expand file tree Collapse file tree 1 file changed +6
-0
lines changed
Expand file tree Collapse file tree 1 file changed +6
-0
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ type pool struct {
2121
2222// Delegate job to a workers
2323// will block if channel is full, you might want to wrap it with goroutine to avoid it
24+ // will panic if called after Stop()
2425func (p * pool ) Delegate (args ... interface {}) {
2526 p .queue <- buildQueueValue (args )
2627}
@@ -35,6 +36,10 @@ func (p *pool) Start(maxWorkers int, fn interface{}) error {
3536 return fmt .Errorf ("%s is not a reflect.Func" , reflect .TypeOf (fn ))
3637 }
3738
39+ if err := p .ctx .Err (); err != nil {
40+ return err
41+ }
42+
3843 for i := 1 ; i <= maxWorkers ; i ++ {
3944 h := reflect .ValueOf (fn )
4045
@@ -55,6 +60,7 @@ func (p *pool) Start(maxWorkers int, fn interface{}) error {
5560
5661// Stop all workers
5762func (p * pool ) Stop () {
63+ defer close (p .queue )
5864 p .cancel ()
5965}
6066
You can’t perform that action at this time.
0 commit comments