1 Star 0 Fork 0

mysoft-free / cron-task

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
channel.go 416 Bytes
一键复制 编辑 原始数据 按行查看 历史
JYoung 提交于 2020-04-24 23:09 . 添加redis的排他锁
package locker
import (
"errors"
"time"
)
type ChannelLocker struct {
ch chan struct{}
lockerWait bool //是否锁等待,false则直接退出
}
func(c *ChannelLocker)AddLock()error{
select{
case c.ch<- struct{}{} :
case <-time.After(time.Millisecond *1):
if !c.lockerWait {
return errors.New("timeout")
}
}
return nil
}
func(c *ChannelLocker)UnLock()error{
<-c.ch
return nil
}
Go
1
https://gitee.com/mysoft-free/cron-task.git
git@gitee.com:mysoft-free/cron-task.git
mysoft-free
cron-task
cron-task
80b3c92effd7

搜索帮助