From 003e5247c7c3d299352b72bdf6b0d620bf9bd453 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Mon, 11 Dec 2023 19:18:36 +0800 Subject: [PATCH] 1 --- task.go | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 task.go 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) +}