37 lines
501 B
Go
37 lines
501 B
Go
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)
|
|
}
|