package main
import (
"fmt"
"github.com/gammazero/workerpool"
"time"
)
func main() {
wp := workerpool.New(2)
requests := []string{"alpha", "beta", "gamma", "delta", "epsilon"}
for _, r := range requests {
wp.Submit(
func(r string ) func(){
return func() {
fmt.Println("Handling request:", r)
time.Sleep(2*time.Second)
}
}(r),
)
}
wp.StopWait()
}
golang worker池
最新推荐文章于 2024-05-01 18:51:25 发布