1
This commit is contained in:
parent
2d79f0c481
commit
003e5247c7
36
task.go
Normal file
36
task.go
Normal 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)
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user