diff --git a/task.go b/task.go new file mode 100644 index 0000000..75789cd --- /dev/null +++ b/task.go @@ -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) +}