Return []error from Stop() channel, allow recursive stop groups

This commit is contained in:
Justin Li
2018-09-09 11:14:24 -04:00
parent 21f500c93e
commit d95120c817
9 changed files with 76 additions and 57 deletions

View File

@@ -7,6 +7,7 @@ import (
"net/http"
"github.com/chihaya/chihaya/pkg/log"
"github.com/chihaya/chihaya/pkg/stop"
"github.com/prometheus/client_golang/prometheus"
)
@@ -17,17 +18,13 @@ type Server struct {
}
// Stop shuts down the server.
func (s *Server) Stop() <-chan error {
c := make(chan error)
func (s *Server) Stop() stop.Result {
c := make(stop.Channel)
go func() {
if err := s.srv.Shutdown(context.Background()); err != nil {
c <- err
} else {
close(c)
}
c.Done(s.srv.Shutdown(context.Background()))
}()
return c
return c.Result()
}
// NewServer creates a new instance of a Prometheus server that asynchronously