Skip to content

Commit

Permalink
fixed error problem
Browse files Browse the repository at this point in the history
  • Loading branch information
chaocai committed Aug 14, 2019
1 parent d4b4f8d commit 2315094
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
11 changes: 11 additions & 0 deletions code/ch41/microkernel/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ func (agt *Agent) startCollectors() error {
var err error
var errs CollectorsError
var mutex sync.Mutex

for name, collector := range agt.collectors {
go func(name string, collector Collector, ctx context.Context) {
defer func() {
Expand All @@ -101,6 +102,9 @@ func (agt *Agent) startCollectors() error {
}
}(name, collector, agt.ctx)
}
if len(errs.CollectorErrors) == 0 {
return nil
}
return errs
}

Expand All @@ -113,6 +117,10 @@ func (agt *Agent) stopCollectors() error {
errors.New(name+":"+err.Error()))
}
}
if len(errs.CollectorErrors) == 0 {
return nil
}

return errs
}

Expand All @@ -125,6 +133,9 @@ func (agt *Agent) destoryCollectors() error {
errors.New(name+":"+err.Error()))
}
}
if len(errs.CollectorErrors) == 0 {
return nil
}
return errs
}

Expand Down
4 changes: 3 additions & 1 deletion code/ch41/microkernel/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ func TestAgent(t *testing.T) {
c2 := NewCollect("c2", "2")
agt.RegisterCollector("c1", c1)
agt.RegisterCollector("c2", c2)
agt.Start()
if err := agt.Start(); err != nil {
fmt.Printf("start error %v\n", err)
}
fmt.Println(agt.Start())
time.Sleep(time.Second * 1)
agt.Stop()
Expand Down

0 comments on commit 2315094

Please sign in to comment.