feat: add progress for task

This commit is contained in:
Noah Hsu
2022-06-18 20:06:45 +08:00
parent 6ad2cf2003
commit adf0178bb7
4 changed files with 29 additions and 25 deletions

View File

@ -8,6 +8,7 @@ import (
)
type Manager struct {
works uint
curID uint64
tasks generic_sync.MapOf[uint64, *Task]
}

View File

@ -17,13 +17,14 @@ var (
type Func func(task *Task) error
type Task struct {
ID uint64
Name string
Status string
Error error
Func Func
Ctx context.Context
cancel context.CancelFunc
ID uint64
Name string
Status string
Error error
Func Func
Progress int
Ctx context.Context
cancel context.CancelFunc
}
func newTask(name string, func_ Func) *Task {
@ -41,6 +42,10 @@ func (t *Task) SetStatus(status string) {
t.Status = status
}
func (t *Task) SetProgress(percentage int) {
t.Progress = percentage
}
func (t *Task) Run() {
t.Status = RUNNING
t.Error = t.Func(t)