Browse Source

refactoring

master
Chakib Benziane 1 year 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.
1. Create a unit manager
2. Implement the `WorkUnit` on your goroutines
3. Add units to the manager
4. Start the manager and wait on its `Quit` channel
4. Run the manager and wait on its `Quit` channel
```golang
import (
@ -81,8 +81,8 @@ func main() {
manager.AddUnit(worker)
manager.AddUnit(worker2)
// Start the manager
go manager.Start()
// Run the manager
go manager.Run()
// Wait for all units to shutdown gracefully through their `Shutdown` method

+ 3
- 3
manager.go View File

@ -12,7 +12,7 @@ import (
var idGen = IdGenerator()
type WorkUnit interface {
Spawn(UnitManager)
Run(UnitManager)
Shutdown()
}
@ -57,12 +57,12 @@ type Manager struct {
panic chan error // Used for panicing goroutines
}
func (m *Manager) Start() {
func (m *Manager) Run() {
log.Println("Starting manager ...")
for unitName, w := range m.workers {
log.Printf("Starting <%s>\n", unitName)
go w.unit.Spawn(w)
go w.unit.Run(w)
}
for {

+ 2
- 2
manager_test.go View File

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

Loading…
Cancel
Save