来个 star 吧, 泛型实现的任务队列
https://github.com/lxzan/concurrency```go
package main
import (
"fmt"
"
github.com/lxzan/concurrency"
"sync/atomic"
)
func main() {
sum := int64(0)
w := concurrency.NewWorkerGroup[int64]()
for i := int64(1); i <= 10; i++ {
w.Push(i)
}
w.OnMessage = func(args int64) error {
fmt.Printf("%v ", args)
atomic.AddInt64(&sum, args)
return nil
}
w.Start()
fmt.Printf("sum=%d\n", sum)
}
```
输出
```
4 5 6 7 8 9 10 1 3 2 sum=55
```