Break listen down in to two parts -- start listening, and wait.
diff --git a/.gitignore b/.gitignore index 48b8bf9..bb125c6 100644 --- a/.gitignore +++ b/.gitignore
@@ -1 +1,4 @@ vendor/ +.idea/ +*.iml +*~
diff --git a/glide.lock b/glide.lock index 910b296..f8b3ba0 100644 --- a/glide.lock +++ b/glide.lock
@@ -1,8 +1,41 @@ hash: 9b96c783f272b0a712add71d2d753d1eb07ba91dfe9b42e3532b8d3e3cec639c -updated: 2016-10-04T12:46:18.025613379-07:00 +updated: 2016-12-16T16:08:14.415655665-08:00 imports: [] testImports: - name: github.com/onsi/ginkgo version: 45a5f6ffb2a14e4f29698c16ae4c0a34018a8951 + subpackages: + - config + - internal/codelocation + - internal/containernode + - internal/failer + - internal/leafnodes + - internal/remote + - internal/spec + - internal/specrunner + - internal/suite + - internal/testingtproxy + - internal/writer + - reporters + - reporters/stenographer + - types - name: github.com/onsi/gomega version: d59fa0ac68bb5dd932ee8d24eed631cdd519efc3 + subpackages: + - format + - internal/assertion + - internal/asyncassertion + - internal/oraclematcher + - internal/testingtsupport + - matchers + - matchers/support/goraph/bipartitegraph + - matchers/support/goraph/edge + - matchers/support/goraph/node + - matchers/support/goraph/util + - types +- name: golang.org/x/sys + version: c200b10b5d5e122be351b67af224adc6128af5bf + subpackages: + - unix +- name: gopkg.in/yaml.v2 + version: a5b47d31c556af34a302ce5d659e6fea44d90de0
diff --git a/scaffold.go b/scaffold.go index a878a7b..9d90a0d 100644 --- a/scaffold.go +++ b/scaffold.go
@@ -317,23 +317,11 @@ } /* -Listen should be called instead of using the standard "http" and "net" +StartListen should be called instead of using the standard "http" and "net" libraries. It will open a port (or ports) and begin listening for -HTTP traffic. It will block until the server is shut down by -the various methods in this class. -It will use the graceful shutdown logic to ensure that once marked down, -the server will not exit until all the requests have completed, -or until the shutdown timeout has expired. -Like http.Serve, this function will block until we are done serving HTTP. -If "SetInsecurePort" or "SetSecurePort" were not set, then it will listen on -a dynamic port. -Listen will block until the server is shutdown using "Shutdown" or one of -the other shutdown mechanisms. It must not be called until after "Open" -has been called. -If shut down, Listen will return the error that was passed to the "shutdown" -method. +HTTP traffic. */ -func (s *HTTPScaffold) Listen(baseHandler http.Handler) error { +func (s *HTTPScaffold) StartListen(baseHandler http.Handler) error { if !s.open { err := s.Open() if err != nil { @@ -366,7 +354,24 @@ if s.secureListener != nil { go http.Serve(s.secureListener, mainHandler) } + return nil +} +/* +WaitForShutdown blocks until we are shut down. +It will use the graceful shutdown logic to ensure that once marked down, +the server will not exit until all the requests have completed, +or until the shutdown timeout has expired. +Like http.Serve, this function will block until we are done serving HTTP. +If "SetInsecurePort" or "SetSecurePort" were not set, then it will listen on +a dynamic port. +This method will block until the server is shutdown using "Shutdown" or one of +the other shutdown mechanisms. It must not be called until after +"StartListenen" +When shut down, this method will return the error that was passed to the "shutdown" +method. +*/ +func (s *HTTPScaffold) WaitForShutdown() error { err := <-s.tracker.C if s.insecureListener != nil { @@ -383,6 +388,19 @@ } /* +Listen is a convenience function that first calls "StartListen" and then +calls "WaitForShutdown." +*/ +func (s *HTTPScaffold) Listen(baseHandler http.Handler) error { + err := s.StartListen(baseHandler) + if err != nil { + return err + } + + return s.WaitForShutdown() +} + +/* Shutdown indicates that the server should stop handling incoming requests and exit from the "Serve" call. This may be called automatically by calling "CatchSignals," or automatically using this call. If