diff options
author | Cory Snider <csnider@mirantis.com> | 2023-02-28 19:59:36 -0500 |
---|---|---|
committer | Cory Snider <csnider@mirantis.com> | 2023-03-01 09:03:34 -0500 |
commit | be39be87f6ae8a94656906ebb2aa7edf4e6d210d (patch) | |
tree | c1890f61b27dc47a8f5161e6ab7145e7520854a7 /api/server | |
parent | a48f19157ad560fcb39e3b10fa0d6c331558998c (diff) | |
download | docker-be39be87f6ae8a94656906ebb2aa7edf4e6d210d.tar.gz |
api/server: delete Wait method
It's surprising that the method to begin serving requests is named Wait.
And it is unidiomatic: it is a synchronous call, but it sends its return
value to the channel passed in as an argument instead of just returning
the value. And ultimately it is just a trivial wrapper around serveAPI.
Export the ServeAPI method instead so callers can decide how to call and
synchronize around it.
Call ServeAPI synchronously on the main goroutine in cmd/dockerd. The
goroutine and channel which the Wait() API demanded are superfluous
after all. The notifyReady() call was always concurrent and asynchronous
with respect to serving the API (its implementation spawns a goroutine)
so it makes no difference whether it is called before ServeAPI() or
after `go ServeAPI()`.
Signed-off-by: Cory Snider <csnider@mirantis.com>
Diffstat (limited to 'api/server')
-rw-r--r-- | api/server/server.go | 17 |
1 files changed, 2 insertions, 15 deletions
diff --git a/api/server/server.go b/api/server/server.go index e8714eb060..c96c84750a 100644 --- a/api/server/server.go +++ b/api/server/server.go @@ -77,9 +77,8 @@ func (s *Server) Close() { } } -// serveAPI loops through all initialized servers and spawns goroutine -// with Serve method for each. It sets createMux() as Handler also. -func (s *Server) serveAPI() error { +// Serve starts listening for inbound requests. +func (s *Server) Serve() error { var chErrors = make(chan error, len(s.servers)) for _, srv := range s.servers { srv.srv.Handler = s.createMux() @@ -194,15 +193,3 @@ func (s *Server) createMux() *mux.Router { return m } - -// Wait blocks the server goroutine until it exits. -// It sends an error message if there is any error during -// the API execution. -func (s *Server) Wait(waitChan chan error) { - if err := s.serveAPI(); err != nil { - logrus.Errorf("ServeAPI error: %v", err) - waitChan <- err - return - } - waitChan <- nil -} |