Browse Source

refactoring

master
Chakib Benziane 11 months ago
parent
commit
2a68eb1323
3 changed files with 8 additions and 8 deletions
  1. 3
    3
      README.md
  2. 3
    3
      manager.go
  3. 2
    2
      manager_test.go

+ 3
- 3
README.md View File

@@ -23,7 +23,7 @@ The `Manager` handles communication and synchronized shutdown procedure.
23 23
 1. Create a unit manager
24 24
 2. Implement the `WorkUnit` on your goroutines
25 25
 3. Add units to the manager
26
-4. Start the manager and wait on its `Quit` channel
26
+4. Run the manager and wait on its `Quit` channel
27 27
 
28 28
 ```golang
29 29
 import (
@@ -81,8 +81,8 @@ func main() {
81 81
     manager.AddUnit(worker)
82 82
     manager.AddUnit(worker2)
83 83
 
84
-    // Start the manager
85
-    go manager.Start()
84
+    // Run the manager
85
+    go manager.Run()
86 86
 
87 87
 
88 88
     // Wait for all units to shutdown gracefully through their `Shutdown` method

+ 3
- 3
manager.go View File

@@ -12,7 +12,7 @@ import (
12 12
 var idGen = IdGenerator()
13 13
 
14 14
 type WorkUnit interface {
15
-	Spawn(UnitManager)
15
+	Run(UnitManager)
16 16
 	Shutdown()
17 17
 }
18 18
 
@@ -57,12 +57,12 @@ type Manager struct {
57 57
 	panic chan error // Used for panicing goroutines
58 58
 }
59 59
 
60
-func (m *Manager) Start() {
60
+func (m *Manager) Run() {
61 61
 	log.Println("Starting manager ...")
62 62
 
63 63
 	for unitName, w := range m.workers {
64 64
 		log.Printf("Starting <%s>\n", unitName)
65
-		go w.unit.Spawn(w)
65
+		go w.unit.Run(w)
66 66
 	}
67 67
 
68 68
 	for {

+ 2
- 2
manager_test.go View File

@@ -13,7 +13,7 @@ var WorkerID int
13 13
 type Worker struct{}
14 14
 
15 15
 // Example loop, it will be spwaned in a goroutine
16
-func (w *Worker) Spawn(um UnitManager) {
16
+func (w *Worker) Run(um UnitManager) {
17 17
 	ticker := time.NewTicker(time.Second)
18 18
 
19 19
 	// Worker's loop
@@ -62,7 +62,7 @@ func DoRunMain(pid chan int, quit chan<- bool) {
62 62
 	manager.AddUnit(worker2)
63 63
 
64 64
 	// Start the manager
65
-	go manager.Start()
65
+	go manager.Run()
66 66
 
67 67
 	// Wait for all units to shutdown gracefully through their `Shutdown` method
68 68
 	quit <- <-manager.Quit

Loading…
Cancel
Save