Open zzjha-cn opened 10 months ago
worker.go中,executeTaskWithTimeout执行有超时限制的任务会死锁。
执行代码:
func main() { var errCount int32 pool := gopool.NewGoPool(100, gopool.WithTimeout(1*time.Second), gopool.WithErrorCallback(func(err error) { fmt.Println("get a error") atomic.StoreInt32(&errCount, 1) })) defer pool.Release() // 超时任务 // pool.AddTask(func() (interface{}, error) { // time.Sleep(2 * time.Second) // return nil, nil // }) // 不超时任务 pool.AddTask(func() (interface{}, error) { fmt.Println("run normal task") return nil, nil }) pool.AddTask(func() (interface{}, error) { fmt.Println("run normal task") return nil, nil }) pool.AddTask(func() (interface{}, error) { fmt.Println("run normal task") return nil, nil }) pool.Wait() fmt.Println("err count:", errCount) }
因为result的chan接收到值后,会在下面等待err的chan 消息,但是此时已经没有发送方了。
worker.go中,executeTaskWithTimeout执行有超时限制的任务会死锁。
执行代码:
因为result的chan接收到值后,会在下面等待err的chan 消息,但是此时已经没有发送方了。