其他分享
首页 > 其他分享> > golang 好用的协程池推荐

golang 好用的协程池推荐

作者:互联网

golang开源的协程池项目:github.com/gammazero/workerpool

下面是一段使用 demo


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 {
      //r := r
      wp.Submit(func() {
         time.Sleep(time.Second * 2)
         fmt.Println("Handling request:", r)
      })
   }

   wp.StopWait()

标签:workerpool,wp,golang,协程池,time,main,好用
来源: https://www.cnblogs.com/hi3254014978/p/16273835.html