2 Star 3 Fork 0

夏午茶 / sgpool

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
spool_example.go 948 Bytes
一键复制 编辑 原始数据 按行查看 历史
gjy 提交于 2020-02-26 11:26 . 目录修改
package main
import (
"fmt"
"math/rand"
"time"
"gitee.com/xiawucha365/sgpool"
)
//======================woker实现===start=====================\\
type workersp struct {
ID string
}
//要执行的任务列表
var name_slices_sp = []string{"001","002","003","004","005","006","007","008","009"}
func (m *workersp) Task() error {
//fmt.Println("job:" + m.ID + "runing...")
timen := rand.Intn(3)
//fmt.Println(timen,"seconds")
time.Sleep(time.Second * time.Duration(timen))
fmt.Println("job:" + m.ID + "over")
return nil
}
//获取任务id,便于
func (m *workersp) GetTaskID() interface{} {
return m.ID
}
//======================woker实现===end=====================\\
//例子演示
func main() {
//创建协程池
spool := sgpool.NewSPool(3, cap(name_slices_sp),2,true)
//提交任务
for _, id := range name_slices_sp {
np := workersp{ID: id}
spool.Commit(&np)
}
spool.Release()
time.Sleep(time.Second * 1)
}
Go
1
https://gitee.com/xiawucha365/sgpool.git
git@gitee.com:xiawucha365/sgpool.git
xiawucha365
sgpool
sgpool
1db674351cbe

搜索帮助