1 Star 0 Fork 0

sy_183 / go-common

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
task.go 802 Bytes
一键复制 编辑 原始数据 按行查看 历史
sy_183 提交于 2023-02-27 19:27 . 纵横视频存储服务v1.1
package task
type Task interface {
Do(interrupter chan struct{}) (interrupted bool)
}
type nopTask struct{}
func Nop() Task {
return nopTask{}
}
func (t nopTask) Do(interrupter chan struct{}) (interrupted bool) { return false }
type interruptedTaskFunc func(interrupter chan struct{}) (interrupted bool)
func Interrupted(fn func(interrupter chan struct{}) (interrupted bool)) Task {
if fn == nil {
return Nop()
}
return interruptedTaskFunc(fn)
}
func (f interruptedTaskFunc) Do(interrupter chan struct{}) (interrupted bool) { return f(interrupter) }
type uninterruptedTaskFunc func()
func Func(fn func()) Task {
if fn == nil {
return Nop()
}
return uninterruptedTaskFunc(fn)
}
func (f uninterruptedTaskFunc) Do(interrupter chan struct{}) (interrupted bool) {
f()
return false
}
1
https://gitee.com/sy_183/go-common.git
git@gitee.com:sy_183/go-common.git
sy_183
go-common
go-common
v1.0.4

搜索帮助