add unit with name

master
blob42 3 months ago
parent f57e69d1a6
commit a396a6a4be

@ -1,11 +1,11 @@
package gum
import (
"fmt"
"log"
"os"
"os/signal"
"reflect"
"strconv"
"strings"
)
@ -149,7 +149,7 @@ func genId() IDGenerator {
}
}
func (m *Manager) AddUnit(unit WorkUnit) {
func (m *Manager) AddUnit(unit WorkUnit, name string) {
workUnitManager := &WorkUnitManager{
workerQuit: make(chan bool, 1),
@ -159,10 +159,10 @@ func (m *Manager) AddUnit(unit WorkUnit) {
}
unitType := reflect.TypeOf(unit)
unitName := strings.Split(unitType.String(), ".")[1]
unitId := idGenerator(unitName)
unitName += strconv.Itoa(unitId)
unitClass := strings.Split(unitType.String(), ".")[1]
unitName := fmt.Sprintf("%s[%s", name, unitClass)
unitID := idGenerator(unitName)
unitName = fmt.Sprintf("%s#%d]", unitName, unitID)
log.Println("Adding unit ", unitName)

@ -60,8 +60,8 @@ func DoRun(pid chan int,
worker2 := NewWorker()
// Register the unit with the manager
manager.AddUnit(worker1)
manager.AddUnit(worker2)
manager.AddUnit(worker1, "")
manager.AddUnit(worker2, "")
// Start the manager
go manager.Run()

Loading…
Cancel
Save