- big refactor tasksch
This commit is contained in:
@@ -2,6 +2,7 @@ package tasksch
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@@ -37,6 +38,7 @@ type ITask interface {
|
||||
|
||||
AddChild(task ITask)
|
||||
GetChildren() TaskList
|
||||
SetParent(parentTask ITask)
|
||||
|
||||
json.Marshaler
|
||||
}
|
||||
@@ -69,6 +71,7 @@ type BaseTask struct {
|
||||
quitChan chan int
|
||||
|
||||
locker sync.RWMutex
|
||||
parent ITask
|
||||
}
|
||||
|
||||
func (s TaskList) Len() int {
|
||||
@@ -199,6 +202,16 @@ func (t *BaseTask) GetChildren() (children TaskList) {
|
||||
return children
|
||||
}
|
||||
|
||||
func (t *BaseTask) SetParent(parentTask ITask) {
|
||||
t.locker.Lock()
|
||||
defer t.locker.Unlock()
|
||||
|
||||
if t.parent != nil {
|
||||
panic(fmt.Sprintf("task:%s already have parent!", utils.Format4Output(t, false)))
|
||||
}
|
||||
t.parent = parentTask
|
||||
}
|
||||
|
||||
/////////
|
||||
|
||||
func (t *BaseTask) MarshalJSON() ([]byte, error) {
|
||||
|
||||
Reference in New Issue
Block a user