- big refactor tasksch

This commit is contained in:
gazebo
2018-10-20 15:05:02 +08:00
parent 2bfa5fe17f
commit 0d5a5189ed
15 changed files with 210 additions and 184 deletions

View File

@@ -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) {