feat: squash multiple modules to one
This commit is contained in:
21
worker-pool/workerpool.go
Normal file
21
worker-pool/workerpool.go
Normal file
@ -0,0 +1,21 @@
|
||||
package workerpool
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func WorkerPool[T any](limit int, worker func(int, T)) chan<- T {
|
||||
tasks := make(chan T, limit)
|
||||
|
||||
for i := 1; i <= limit; i++ {
|
||||
go func(i int) {
|
||||
defer fmt.Printf("worker:%d done\n", i)
|
||||
|
||||
for t := range tasks {
|
||||
worker(i, t)
|
||||
}
|
||||
}(i)
|
||||
}
|
||||
|
||||
return tasks
|
||||
}
|
Reference in New Issue
Block a user