代码拉取完成,页面将自动刷新
package queue
import (
"gitee.com/h79/goutils/common/system"
"sync"
"time"
)
type Call struct {
PopCount int
Duration time.Duration
Wait func(dur time.Duration)
Begin func(count int) any
Process func(be any, data any)
Quited func(lock sync.Locker, qu Queue)
}
func Run(c Call, 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)
}
}
if c.Quited == nil {
c.Quited = func(lock sync.Locker, qu Queue) {
}
}
ten := make([]any, 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)
select {
case <-system.Closed():
c.Quited(lock, qu)
return
default:
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。