How to close the goruntime in the pool
wangxin0814 opened this issue · 0 comments
wangxin0814 commented
`numCPUs := runtime.NumCPU()
pool := tunny.NewFunc(numCPUs, func(in interface{}) interface{} {
intVal := in.(int)
fmt.Println("first", in)
time.Sleep(3 * time.Second)
fmt.Println("second", in)
return intVal * 2
})
defer pool.Close()
ctx, cancel := context.WithCancel(context.Background())
pool.ProcessCtx(ctx, 10)
time.Sleep(2 * time.Second)
cancel()`
first 10
second 10