1 Star 0 Fork 0

h79/goutils

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
run.go 752 Bytes
一键复制 编辑 原始数据 按行查看 历史
huqiuyun 提交于 2023-02-28 14:31 . run
package queue
import (
"sync"
"time"
)
type RunCall struct {
PopCount int
Duration time.Duration
Wait func(dur time.Duration)
Begin func(count int) interface{}
Process func(be interface{}, data interface{})
}
func Run(c RunCall, lock sync.Locker, qu Queue) {
var count int
var popCount = c.PopCount
if popCount <= 0 {
popCount = 10
}
if c.Wait == nil {
c.Wait = func(dur time.Duration) {
time.Sleep(dur)
}
}
ten := make([]interface{}, popCount)
for {
count = 0
lock.Lock()
for i := 0; i < popCount; i++ {
v := qu.Pop()
if v == nil {
break
}
ten[i] = v
count++
}
lock.Unlock()
var bn = c.Begin(count)
for i := 0; i < count; i++ {
c.Process(bn, ten[i])
}
c.Wait(c.Duration)
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/h79/goutils.git
git@gitee.com:h79/goutils.git
h79
goutils
goutils
v1.10.1

搜索帮助