This commit is contained in:
aozhiwei 2023-12-11 19:18:36 +08:00
parent 2d79f0c481
commit 003e5247c7

36
task.go Normal file
View File

@ -0,0 +1,36 @@
package f5
type Task struct {
status int32
}
func (this *Task) IsRunning() bool {
return this.status == 0
}
func (this *Task) IsSucc() bool {
return this.status > 0
}
func (this *Task) IsFail() bool {
return this.status < 0
}
func (this *Task) SetSucc() {
this.status = 1
}
func (this *Task) SetFail() {
this.status = -1
}
func (this *Task) run(cb func(*Task)) *Task {
for this.IsRunning() {
cb(this)
}
return this
}
func NewTask(cb func(*Task)) *Task {
return new(Task).run(cb)
}